\lmcsdoi

2045 \lmcsheadingLABEL:LastPageOct. 05, 2023Oct. 07, 2024

[a] [c] [b]

Fair Asynchronous Session Subtyping

Mario Bravetti\lmcsorcid0000-0001-5193-2914 Julien Lange\lmcsorcid0000-0001-9697-1378  and  Gianluigi Zavattaro\lmcsorcid0000-0003-3313-6409 University of Bologna, ITALY [email protected] University of Bologna / INRIA OLAS Team, ITALY [email protected] Royal Holloway, University of London, Egham, UK [email protected]
Abstract.

Session types are widely used as abstractions of asynchronous message passing systems. Refinement for such abstractions is crucial as it allows improvements of a given component without compromising its compatibility with the rest of the system. In the context of session types, the most general notion of refinement is asynchronous session subtyping, which allows message emissions to be anticipated w.r.t. a bounded amount of message consumptions. In this paper we investigate the possibility to anticipate emissions w.r.t. an unbounded amount of consumptions: to this aim we propose to consider fair compliance over asynchronous session types and fair refinement as the relation that preserves it. This allows us to propose a novel variant of session subtyping that leverages the notion of controllability from service contract theory and that is a sound characterisation of fair refinement. In addition, we show that both fair refinement and our novel subtyping are undecidable. We also present a sound algorithm which deals with examples that feature potentially unbounded buffering. Finally, we present an implementation of our algorithm and an empirical evaluation of it on synthetic benchmarks.

This work has been partially supported by the research project FREEDA (CUP: I53D23003550006) funded by the framework PRIN 2022 (MUR, Italy), the French ANR project SmartCloud ANR-23-CE25-0012, and the H2020-MSCA-RISE project ID 778233 “Behavioural Application Program Interfaces (BEHAPI)”

1. Introduction

The coordination of software components via message-passing techniques is becoming increasingly popular in modern programming languages and development methodologies based on actors and microservices, e.g., Rust, Go, and the Twelve-Factor App methodology [twelvefactor]. Often the communication between two concurrent or distributed components takes place over point-to-point fifo channels.

Abstract models such as communicating finite-state machines [BZ83] and asynchronous session types [HYC16] are essential to reason about the correctness of such systems in a rigorous way. In particular these models are important to reason about mathematically grounded techniques to improve concurrent and distributed systems in a compositional way. The key question is whether a component can be refined independently of the others, without compromising the correctness of the whole system. In the theory of session types, the most general notion of refinement is the asynchronous session subtyping [ESOP09, CDY2014, MariangiolaPreciness], which leverages asynchrony by allowing the refined component to anticipate message emissions, but only under certain conditions. Notably asynchronous session subtyping rules out candidate subtypes that occur naturally in communication protocols where, e.g., two parties simultaneously send each other a finite but unspecified amount of messages before removing them from their buffers.

We illustrate this key limitation of the asynchronous session subtyping with Figure 1, which depicts possible communication protocols between a spacecraft and a ground station that communicate via two unbounded asynchronous channels (one in each direction). For convenience, the protocols are represented as session types (bottom) and equivalent communicating finite-state machines (top). Consider TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT and TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT first. Session type TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT is the abstraction of the spacecraft. It may send a finite but unspecified number of telemetries (𝑡𝑚𝑡𝑚\mathit{tm}italic_tm), followed by a message 𝑜𝑣𝑒𝑟𝑜𝑣𝑒𝑟\mathit{over}italic_over — this phase of the protocol typically models a for loop and its exit. In the second phase, the spacecraft receives a number of telecommands (𝑡𝑐𝑡𝑐\mathit{tc}italic_tc), followed by a message 𝑑𝑜𝑛𝑒𝑑𝑜𝑛𝑒\mathit{done}italic_done. Session type TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT is the abstraction of the ground station. It is the dual of TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT, written TS¯¯subscript𝑇𝑆\overline{T_{S}}over¯ start_ARG italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT end_ARG, as required in standard binary session types without subtyping. Since TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT and TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT are dual of each other, the theory of session types guarantees that they form a correct composition, namely no communication errors can be generated and the communication protocol can always terminate successfully, with empty queues.

However, it is clear that this protocol is not efficient: the communication is half-duplex, i.e., it is never the case that more than one party is sending at any given time. Using full-duplex communication is crucial in distributed systems with intermittent connectivity, e.g., in this case ground stations are not always visible from low orbit satellites.

The abstraction of a more efficient ground station is given by type TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT, which sends telecommands before receiving telemetries. In this way TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT and TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT interact in a symmetric manner: they first send all of their messages and then consume the messages sent from the other partner. No communication error can occur, and the communication protocol can always terminate successfully, with empty queues. Unfortunately TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT is not an asynchronous subtype of TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT according to earlier definitions of session subtyping [ESOP09, MariangiolaPreciness, CDY2014]. Hence they cannot formally guarantee that TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT is a safe replacement for TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT. Note that the composition of TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT and TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT is not existentially bounded, hence it cannot be verified by techniques based on communicating finite-state machines [LangeY19, BouajjaniEJQ18, GenestKM06, GenestKM07].

0011112222!𝑡𝑐!{\mathit{\mathit{tc}}}! italic_tc!𝑑𝑜𝑛𝑒!{\mathit{\mathit{done}}}! italic_done?𝑡𝑚?𝑡𝑚?\mathit{\mathit{tm}}? italic_tm?𝑜𝑣𝑒𝑟?𝑜𝑣𝑒𝑟?\mathit{\mathit{over}}? italic_over 0011112222?𝑡𝑚?𝑡𝑚?\mathit{\mathit{tm}}? italic_tm?𝑜𝑣𝑒𝑟?𝑜𝑣𝑒𝑟?\mathit{\mathit{over}}? italic_over!𝑡𝑐!{\mathit{\mathit{tc}}}! italic_tc!𝑑𝑜𝑛𝑒!{\mathit{\mathit{done}}}! italic_done 0011112222!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done
TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT TG=TS¯subscript𝑇𝐺¯subscript𝑇𝑆T_{G}=\overline{T_{S}}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT = over¯ start_ARG italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT end_ARG TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT
TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT = μ𝐭.{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:μ𝐭.&{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝}}\mu\mathbf{t}.\oplus\{\mathit{tc}:\mathbf{t},\mathit{done}:\mu\mathbf{t^{% \prime}}.~{}\&\{\mathit{tm}:\mathbf{t^{\prime}},\mathit{over}:\mathbf{end}\}\}italic_μ bold_t . ⊕ { italic_tc : bold_t , italic_done : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tm : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_over : bold_end } }
TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT = μ𝐭.&{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:μ𝐭.{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}}\mu\mathbf{t}.~{}\&\{\mathit{tm}:\mathbf{t},\mathit{over}:\mu\mathbf{t^{\prime% }}.\oplus\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:\mathbf{end}\}\}italic_μ bold_t . & { italic_tm : bold_t , italic_over : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . ⊕ { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } }
TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT = μ𝐭.{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}}\mu\mathbf{t}.\oplus\{\mathit{tm}:\mathbf{t},\mathit{over}:\mu\mathbf{t^{% \prime}}.~{}\&\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:\mathbf{end}\}\}italic_μ bold_t . ⊕ { italic_tm : bold_t , italic_over : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } }
Figure 1. Satellite protocols. TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT is the refined session type of the ground station, TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT is the session type of ground station, and TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT is the session type of the spacecraft.

Technically speaking, previous asynchronous session subtyping relations do not capture our spacecraft example due to the notion of correct composition that they consider. For instance, the notion of correct composition considered in [MariangiolaPreciness] imposes that all sent messages are guaranteed to be consumed along all possible computations of the receiver. Following this approach the above type TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT is not a correct refinement of TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT because TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT can start by performing infinitely many outputs without consuming any incoming message.

The alternative notion of correct composition that we consider is weaker in that we do not impose a sent message to be consumed along all possible paths of the receiver, but we only require that, for all possible computation of the receiver either the message has been already consumed or there exists a continuation of the computation in which the message will be consumed. More precisely, our notion of correctness is as follows: given the composition of two session types, for every computation there always exists a continuation of such computation reaching successful termination (with empty queues). This is a reasonable assumption, e.g., for programs that can conceptually run indefinitely but must account for graceful termination (e.g., to release acquired resources).

According to this notion of correct composition, TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT and TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT are correct partners in that for every reachable state, we can always find a way to terminate successfully the interaction. This way to termination can be selected by exiting from the initial loops of outputs of both TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT and TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT. The theory that we will develop will allow us to conclude that TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT is a correct refinement of TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT for every possible partner, not only for the partner TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT.

The use of this notion of correct composition is new in the context of asynchronous session types, but it has been already considered in several related contexts. First of all, we observe that according to the terminology in [GlabbeekH19], our notion of correctness coincides with imposing that successful termination is a liveness-property which holds under the assumption of full fairness. For this reason, we name fair compliance our notion of correct composition. Fair compliance has been already considered in the context of synchronous session types [Padovani16, CicconeP22], in the definition of should testing [RV07] where “every reachable state is required to be on a path to success”, and applied also to behavioural contracts [BravettiZ08, wsfm08].

Given our notion of fair compliance defined on an operational model for asynchronous session types, we define fair refinement the refinement relation that preserves it. Then, we propose a novel variant of session subtyping called fair asynchronous session subtyping, that leverages the notion of controllability from service contract theory, and which is a sound characterisation of fair refinement. We show that both fair refinement and fair asynchronous session subtyping are undecidable, but give a sound algorithm for the latter. Our algorithm covers session types that exhibit complex behaviours (including the spacecraft example and variants). Our algorithm has been implemented in a tool available online [tool].

Structure of the paper

The rest of this paper is structured as follows. In § 2 we recall syntax and semantics of asynchronous session types, we define fair compliance and the corresponding fair refinement. In § 3 we introduce fair asynchronous subtyping, the first relation of its kind to deal with examples such as those in Figure 1. In § 4 we propose a sound algorithm for subtyping that supports examples with unbounded accumulations, including the ones discussed in this paper. In § 5 we discuss the implementation of this algorithm. In § 6 we present an evaluation of our implementation on generated session types. Finally, in § 7 we discuss related and future work. The paper includes also an the appendix containing details of proofs that are not necessary in order to understand the main results that we have proved and the corresponding proof techniques.

This paper is based on the conference publication [BravettiLZ21]. The main novelties w.r.t. [BravettiLZ21] are: the inclusion of all the proofs of our results, a completely new empirical evaluation of the implementation of our algorithm for checking fair asynchronous session subtyping (see § 6), an enriched and more comprehensive related work section.

2. Fair Refinement for Asynchronous Session Types

In this section we first recall the syntax of two-party session types, their reduction semantics, and a notion of compliance centred on the successful termination of interactions. We define our notion of refinement based on this compliance and show that it is generally undecidable whether a type is a refinement of another.

2.1. Preliminaries: Binary Session Types

Syntax

The formal syntax of two-party session types is given below. We follow the simplified notation used in, e.g., [BravettiCZ17, BCZ18], without dedicated constructs for sending an output/receiving an input. Additionally we abstract away from message payloads since they are orthogonal to the results of this paper.

{defi}

[Session Types] Given a set of labels \mathcal{L}caligraphic_L, ranged over by l𝑙litalic_l, the syntax of two-party session types is given by the following grammar:

T::={li:Ti}iI&{li:Ti}iIμ𝐭.T𝐭𝐞𝐧𝐝\begin{array}[]{lrl}T&::=&\ \ \oplus\{{l}_{i}:{T}_{i}\}_{i\in I}\quad\mid\quad% \&\{{l}_{i}:{T}_{i}\}_{i\in I}\quad\mid\quad\mu\mathbf{t}.T\quad\mid\quad% \mathbf{t}\quad\mid\quad\mathbf{end}\end{array}start_ARRAY start_ROW start_CELL italic_T end_CELL start_CELL : := end_CELL start_CELL ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT ∣ & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT ∣ italic_μ bold_t . italic_T ∣ bold_t ∣ bold_end end_CELL end_ROW end_ARRAY

Output selection {li:Ti}iIdirect-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼\oplus\{{l}_{i}:{T}_{i}\}_{i\in I}⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT represents a guarded internal choice, specifying that a label lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT is sent over a channel, then continuation Tisubscript𝑇𝑖T_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT is executed. Input branching &{li:Ti}iIsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼\&\{{l}_{i}:{T}_{i}\}_{i\in I}& { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT represents a guarded external choice, specifying a protocol that waits for messages. If message lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT is received, continuation Tisubscript𝑇𝑖T_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT takes place. In selections and branchings each branch is tagged by a label lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT, taken from a global set of labels \mathcal{L}caligraphic_L. In each selection/branching, these labels are assumed to be pairwise distinct. In what follows, we leave implicit the index set iI𝑖𝐼i\in Iitalic_i ∈ italic_I in input branchings and output selections when it is clear from the context. Types μ𝐭.Tformulae-sequence𝜇𝐭𝑇\mu\mathbf{t}.Titalic_μ bold_t . italic_T and 𝐭𝐭\mathbf{t}bold_t denote standard recursion constructs. We assume recursion to be guarded in session types, i.e., in μ𝐭.Tformulae-sequence𝜇𝐭𝑇\mu\mathbf{t}.Titalic_μ bold_t . italic_T, the recursion variable 𝐭𝐭\mathbf{t}bold_t occurs within the scope of a selection or branching. Session types are closed, i.e., all recursion variables 𝐭𝐭\mathbf{t}bold_t occur under the scope of a corresponding binder μ𝐭.Tformulae-sequence𝜇𝐭𝑇\mu\mathbf{t}.Titalic_μ bold_t . italic_T. Terms of the session syntax that are not closed are dubbed (session) terms. Type 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end denotes the end of the interactions.

The dual of session type T𝑇Titalic_T, written T¯¯𝑇\overline{T}over¯ start_ARG italic_T end_ARG, is inductively defined as follows: {li:Ti}iI¯=&{li:T¯i}iI¯direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼subscriptconditional-setsubscript𝑙𝑖subscript¯𝑇𝑖𝑖𝐼\overline{\oplus\{{l}_{i}:{T}_{i}\}_{i\in I}}=\&\{{l}_{i}:{\overline{T}}_{i}\}% _{i\in I}over¯ start_ARG ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT end_ARG = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : over¯ start_ARG italic_T end_ARG start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT, &{li:Ti}iI¯={li:T¯i}iI¯subscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript¯𝑇𝑖𝑖𝐼\overline{\&\{{l}_{i}:{T}_{i}\}_{i\in I}}=\oplus\{{l}_{i}:{\overline{T}}_{i}\}% _{i\in I}over¯ start_ARG & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT end_ARG = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : over¯ start_ARG italic_T end_ARG start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT, 𝐞𝐧𝐝¯=𝐞𝐧𝐝¯𝐞𝐧𝐝𝐞𝐧𝐝\overline{\mathbf{end}}=\mathbf{end}over¯ start_ARG bold_end end_ARG = bold_end, 𝐭¯=𝐭¯𝐭𝐭\overline{\mathbf{t}}=\mathbf{t}over¯ start_ARG bold_t end_ARG = bold_t, and μ𝐭.T¯=μ𝐭.T¯formulae-sequence¯formulae-sequence𝜇𝐭𝑇𝜇𝐭¯𝑇\overline{\mu\mathbf{t}.T}=\mu\mathbf{t}.\overline{T}over¯ start_ARG italic_μ bold_t . italic_T end_ARG = italic_μ bold_t . over¯ start_ARG italic_T end_ARG.

2.2. Asynchronous Fair Refinement

We now define our notion of fair refinement. We first define a reduction semantics formalizing the interaction between two binary session types assuming asynchronous communication via FIFO buffers. Then we formalize the notion of successful final configuration; intuitively a configuration is successful if both communicating types have completed their send/receive operations and the buffers are empty. Compliance is then defined as follows: two session types are compliant if, for every reachable configuration (according to the reduction semantics), the interaction can continue to reach a successful configuration. Finally, we say that a type T𝑇Titalic_T refines another type S𝑆Sitalic_S if it can safely replace S𝑆Sitalic_S, i.e., if S𝑆Sitalic_S is compliant with a type Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT then also T𝑇Titalic_T is compliant with Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

In the definition of the reduction semantics for types we need some auxiliary notation. Hereafter, we let ω𝜔\omegaitalic_ω range over words in superscript\mathcal{L}^{\ast}caligraphic_L start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT, write ϵitalic-ϵ\epsilonitalic_ϵ for the empty word, and write ω1ω2subscript𝜔1subscript𝜔2\omega_{1}\!\cdot\!\omega_{2}italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋅ italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT for the concatenation of words ω1subscript𝜔1\omega_{1}italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and ω2subscript𝜔2\omega_{2}italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT, where each word may contain zero or more labels. Also, we write T{T/𝐭}𝑇superscript𝑇𝐭T\{\nicefrac{{T^{\prime}}}{{\mathbf{t}}}\}italic_T { / start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_ARG start_ARG bold_t end_ARG } for T𝑇Titalic_T where every free occurrence of 𝐭𝐭\mathbf{t}bold_t is replaced by Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

We give an asynchronous semantics of session types via transition systems whose states are configurations of the form: [T1,ω1]|[T2,ω2]conditionalsubscript𝑇1subscript𝜔1subscript𝑇2subscript𝜔2[T_{1},\omega_{1}]|[T_{2},\omega_{2}][ italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ] where T1subscript𝑇1T_{1}italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and T2subscript𝑇2T_{2}italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT are session types equipped with two sequences ω1subscript𝜔1\omega_{1}italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and ω2subscript𝜔2\omega_{2}italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT of incoming messages (representing unbounded buffers). We use s𝑠sitalic_s, ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, etc. to range over configurations.

In this paper, we use explicit unfoldings of session types, as defined below. {defi}[Unfolding] Given session type T𝑇Titalic_T, we define 𝗎𝗇𝖿𝗈𝗅𝖽(T)𝗎𝗇𝖿𝗈𝗅𝖽𝑇\mathsf{unfold}(T)sansserif_unfold ( italic_T ):

𝗎𝗇𝖿𝗈𝗅𝖽(T)={𝗎𝗇𝖿𝗈𝗅𝖽(T{T/𝐭})if T=μ𝐭.TTotherwise𝗎𝗇𝖿𝗈𝗅𝖽𝑇cases𝗎𝗇𝖿𝗈𝗅𝖽superscript𝑇𝑇𝐭if T=μ𝐭.T𝑇otherwise\mathsf{unfold}(T)=\begin{cases}\mathsf{unfold}(T^{\prime}\{\nicefrac{{T}}{{% \mathbf{t}}}\})&\text{if $T=\mu\mathbf{t}.T^{\prime}$}\\ T&\text{otherwise}\end{cases}sansserif_unfold ( italic_T ) = { start_ROW start_CELL sansserif_unfold ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT { / start_ARG italic_T end_ARG start_ARG bold_t end_ARG } ) end_CELL start_CELL if italic_T = italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_CELL end_ROW start_ROW start_CELL italic_T end_CELL start_CELL otherwise end_CELL end_ROW

Definition 2.2 is standard — an equivalent function is used in the first session subtyping [GH05]. Notice that 𝗎𝗇𝖿𝗈𝗅𝖽(T)𝗎𝗇𝖿𝗈𝗅𝖽𝑇\mathsf{unfold}(T)sansserif_unfold ( italic_T ) unfolds all the recursive definitions in front of T𝑇Titalic_T, and it is well defined for session types with guarded recursion (c.f. assumptions in Section 2.1).

{defi}

[Transition Relation] The transition relation \rightarrow over configurations is the minimal relation satisfying the rules below (plus symmetric ones):

  1. (1)

    if jI𝑗𝐼j\in Iitalic_j ∈ italic_I then [{li:Ti}iI,ω1]|[T2,ω2][Tj,ω1]|[T2,ω2lj]conditionaldirect-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼subscript𝜔1subscript𝑇2subscript𝜔2conditionalsubscript𝑇𝑗subscript𝜔1subscript𝑇2subscript𝜔2subscript𝑙𝑗[\oplus\{{l}_{i}:{T}_{i}\}_{i\in I},\omega_{1}]|[T_{2},\omega_{2}]\rightarrow[% T_{j},\omega_{1}]|[T_{2},\omega_{2}\!\cdot\!l_{j}][ ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ] → [ italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ];

  2. (2)

    if jI𝑗𝐼j\in Iitalic_j ∈ italic_I then [&{li:Ti}iI,ljω1]|[T2,ω2][Tj,ω1]|[T2,ω2]conditionalsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼subscript𝑙𝑗subscript𝜔1subscript𝑇2subscript𝜔2conditionalsubscript𝑇𝑗subscript𝜔1subscript𝑇2subscript𝜔2[\&\{{l}_{i}:{T}_{i}\}_{i\in I},l_{j}\!\cdot\!\omega_{1}]|[T_{2},\omega_{2}]% \rightarrow[T_{j},\omega_{1}]|[T_{2},\omega_{2}][ & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT , italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⋅ italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ] → [ italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ];

  3. (3)

    if [𝗎𝗇𝖿𝗈𝗅𝖽(T1),ω1]|[T2,ω2]sconditional𝗎𝗇𝖿𝗈𝗅𝖽subscript𝑇1subscript𝜔1subscript𝑇2subscript𝜔2𝑠[\mathsf{unfold}(T_{1}),\omega_{1}]|[T_{2},\omega_{2}]\rightarrow s[ sansserif_unfold ( italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ) , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ] → italic_s then [T1,ω1]|[T2,ω2]sconditionalsubscript𝑇1subscript𝜔1subscript𝑇2subscript𝜔2𝑠[T_{1},\omega_{1}]|[T_{2},\omega_{2}]\rightarrow s[ italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ] → italic_s.

We write superscript\rightarrow^{*}→ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT for the reflexive and transitive closure of the \rightarrow relation. Intuitively a configuration s𝑠sitalic_s reduces to configuration ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT when either (1) a type outputs a message ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT, which is added at the end of its partner’s queue; (2) a type consumes an expected message ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT from the head of its queue; or (3) the unfolding of a type can execute one of the transitions above.

Next, we define successful configurations as those configurations where both types have terminated (reaching 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end) and both queues are empty. We use this to give our definition of compliance which holds when it is possible to reach a successful configuration from all reachable configurations. {defi}[Successful Configuration] The notion of successful configuration is formalised by a predicate s𝑠square-roots\surditalic_s √ defined as follows:

[T,ωT]|[S,ωS]iff𝗎𝗇𝖿𝗈𝗅𝖽(T)=𝗎𝗇𝖿𝗈𝗅𝖽(S)=𝐞𝐧𝐝 and ωT=ωS=ϵconditional𝑇subscript𝜔𝑇𝑆subscript𝜔𝑆iff𝗎𝗇𝖿𝗈𝗅𝖽𝑇𝗎𝗇𝖿𝗈𝗅𝖽𝑆𝐞𝐧𝐝 and subscript𝜔𝑇subscript𝜔𝑆italic-ϵ[T,\omega_{T}]|[S,\omega_{S}]\surd\;\;\mbox{iff}\;\;\mathsf{unfold}(T)\!=\!% \mathsf{unfold}(S)\!=\!\mathbf{end}\ \text{ and }\ \omega_{T}\!=\!\omega_{S}\!% =\!\epsilon[ italic_T , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] √ iff sansserif_unfold ( italic_T ) = sansserif_unfold ( italic_S ) = bold_end and italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT = italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT = italic_ϵ
{defi}

[Compliance] Given a configuration s𝑠sitalic_s we say that it is a correct composition if, whenever sssuperscript𝑠superscript𝑠s\rightarrow^{*}s^{\prime}italic_s → start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, there exists a configuration s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that ss′′superscriptsuperscript𝑠superscript𝑠′′s^{\prime}\rightarrow^{\ast}s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT → start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT and s′′superscript𝑠′′square-roots^{\prime\prime}\surditalic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT √.

Two session types T𝑇Titalic_T and S𝑆Sitalic_S are compliant if [T,ϵ]|[S,ϵ]conditional𝑇italic-ϵ𝑆italic-ϵ[T,\epsilon]|[S,\epsilon][ italic_T , italic_ϵ ] | [ italic_S , italic_ϵ ] is a correct composition.

Observe that our definition of compliance is stronger than what is generally considered in the literature on session types, e.g., [LangeY19, LY17, DY13], where two types are deemed compliant if all messages that are sent are eventually received, and each non-terminated type can always eventually make a move. Compliance is analogous to the notion of correct session in [Padovani16] but in an asynchronous setting.

A consequence of Definition 2.2 is that it is generally not the case that a session type T𝑇Titalic_T is compliant with its dual T¯¯𝑇\overline{T}over¯ start_ARG italic_T end_ARG, as we show in the example below. {exa} The session type T=&{l1:𝐞𝐧𝐝,l2:μ𝐭.{l3:𝐭}}T=\&\{l_{1}:\mathbf{end},\ l_{2}:\mu\mathbf{t}.\oplus\{l_{3}:\mathbf{t}\}\}italic_T = & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_end , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : italic_μ bold_t . ⊕ { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_t } } and its dual T¯={l1:𝐞𝐧𝐝,l2:μ𝐭.&{l3:𝐭}}\overline{T}=\oplus\{l_{1}:\mathbf{end},\ l_{2}:\mu\mathbf{t}.\&\{l_{3}:% \mathbf{t}\}\}over¯ start_ARG italic_T end_ARG = ⊕ { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_end , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_t } } are not compliant. Indeed, when T¯¯𝑇\overline{T}over¯ start_ARG italic_T end_ARG sends label l2subscript𝑙2l_{2}italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT, the configuration [𝐞𝐧𝐝,ϵ]|[𝐞𝐧𝐝,ϵ]conditional𝐞𝐧𝐝italic-ϵ𝐞𝐧𝐝italic-ϵ[\mathbf{end},\epsilon]|[\mathbf{end},\epsilon][ bold_end , italic_ϵ ] | [ bold_end , italic_ϵ ] is no longer reachable.

We introduce a notion of refinement that preserves compliance. This follows previous work done in the context of behavioural contracts [BravettiZ08] and synchronous multi-party session types [Padovani16]. The key difference with these works is that we are considering asynchronous communication based on (unbounded) fifo queues. Asynchrony makes fair refinement undecidable, as we show below.

{defi}

[Refinement] A session type T𝑇Titalic_T refines S𝑆Sitalic_S, written TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S, if for every Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT s.t. S𝑆Sitalic_S and Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT are compliant then T𝑇Titalic_T and Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT are also compliant. In contrast to traditional (synchronous and asynchronous) subtyping for session types [GH05, MariangiolaPreciness, ESOP09], this refinement is not covariant on outputs, i.e., it does not always allow a refined type to have output selections with less labels.111The synchronous subtyping in [GH05] follows a channel-oriented approach; hence it has the opposite direction and is contravariant on outputs.

{exa}

Let T=μ𝐭.{l1:𝐭}formulae-sequence𝑇𝜇𝐭direct-sumconditional-setsubscript𝑙1𝐭T=\mu\mathbf{t}.\oplus\{l_{1}:\mathbf{t}\}italic_T = italic_μ bold_t . ⊕ { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t } and S=μ𝐭.{l1:𝐭,l2:𝐞𝐧𝐝}formulae-sequence𝑆𝜇𝐭direct-sumconditional-setsubscript𝑙1:𝐭subscript𝑙2𝐞𝐧𝐝S=\mu\mathbf{t}.\oplus\{l_{1}:\mathbf{t},\ l_{2}:\mathbf{end}\}italic_S = italic_μ bold_t . ⊕ { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : bold_end }. We have that T𝑇Titalic_T is a synchronous (and asynchronous) subtype of S𝑆Sitalic_S. However T𝑇Titalic_T is not a refinement of S𝑆Sitalic_S. In particular, the type S¯=μ𝐭.&{l1:𝐭,l2:𝐞𝐧𝐝}formulae-sequence¯𝑆𝜇𝐭conditional-setsubscript𝑙1:𝐭subscript𝑙2𝐞𝐧𝐝\overline{S}=\mu\mathbf{t}.~{}\&\{l_{1}:\mathbf{t},\ l_{2}:\mathbf{end}\}over¯ start_ARG italic_S end_ARG = italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : bold_end } is compliant with S𝑆Sitalic_S but not with T𝑇Titalic_T, since T𝑇Titalic_T does not terminate.

2.3. Undecidability of Fair Refinement

Next, we show that the refinement relation square-image-of-or-equals\sqsubseteq is generally undecidable. The proof of undecidability exploits results from the tradition of computability theory, i.e., Turing completeness of queue machines. The crux of the proof is to reduce the problem of checking the reachability of a given state in a queue machine to the problem of checking the refinement between two session types.

Preliminaries

Below we consider only state reachability in queue machines, and not the typical notion of the language recognised by a queue machine (see, e.g., [BravettiCZ17] for a formalisation of queue machines). Hence, we use a simplified formalisation, where no input string is considered.

{defi}

[Queue Machine] A queue machine M𝑀Mitalic_M is defined by a five-tuple (Q,Γ,$,s,δ)𝑄Γcurrency-dollar𝑠𝛿(Q,\Gamma,\$,s,\delta)( italic_Q , roman_Γ , $ , italic_s , italic_δ ) where:

  • Q𝑄Qitalic_Q is a finite set of states;

  • ΓΓ\Gammaroman_Γ is a finite set denoting the queue alphabet (ranged over by A,B,C,X𝐴𝐵𝐶𝑋A,B,C,Xitalic_A , italic_B , italic_C , italic_X);

  • $Γcurrency-dollarΓ\$\in\Gamma$ ∈ roman_Γ is the initial queue symbol;

  • sQ𝑠𝑄s\in Qitalic_s ∈ italic_Q is the start state;

  • δ:Q×ΓQ×Γ:𝛿𝑄Γ𝑄superscriptΓ\delta:Q\times\Gamma\rightarrow Q\times\Gamma^{*}italic_δ : italic_Q × roman_Γ → italic_Q × roman_Γ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT is the transition function (ΓsuperscriptΓ\Gamma^{*}roman_Γ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT is the set of sequences of symbols in ΓΓ\Gammaroman_Γ).

Considering a queue machine M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ), a configuration of M𝑀Mitalic_M is an ordered pair (q,γ)𝑞𝛾(q,\gamma)( italic_q , italic_γ ) where qQ𝑞𝑄q\in Qitalic_q ∈ italic_Q is its current state and γΓ𝛾superscriptΓ\gamma\in\Gamma^{*}italic_γ ∈ roman_Γ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT is the queue. The starting configuration is (s,$)𝑠currency-dollar(s,\$)( italic_s , $ ), consisting of the start state s𝑠sitalic_s and the initial queue symbol $currency-dollar\$$.

Next, we define the transition relation (Msubscript𝑀\rightarrow_{M}→ start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT), leading a configuration to another, and the related notion of state reachability. {defi}[State Reachability] Given a machine M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M\!\!=\!\!(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ), the transition relation Msubscript𝑀\rightarrow_{M}→ start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT over configurations Q×Γ𝑄superscriptΓQ\times\Gamma^{*}italic_Q × roman_Γ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT is defined as follows. For p,qQ𝑝𝑞𝑄p,q\in Qitalic_p , italic_q ∈ italic_Q, AΓ𝐴ΓA\in\Gammaitalic_A ∈ roman_Γ, and α,γΓ𝛼𝛾superscriptΓ\alpha,\gamma\in\Gamma^{*}italic_α , italic_γ ∈ roman_Γ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT, we have (p,Aα)M(q,αγ)subscript𝑀𝑝𝐴𝛼𝑞𝛼𝛾(p,A\alpha)\rightarrow_{M}(q,\alpha\gamma)( italic_p , italic_A italic_α ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT ( italic_q , italic_α italic_γ ) whenever δ(p,A)=(q,γ)𝛿𝑝𝐴𝑞𝛾\delta(p,A)=(q,\gamma)italic_δ ( italic_p , italic_A ) = ( italic_q , italic_γ ). Let Msuperscriptsubscript𝑀\rightarrow_{M}^{*}→ start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT be the reflexive and transitive closure of Msubscript𝑀\rightarrow_{M}→ start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT.

A target state qfQsubscript𝑞𝑓𝑄q_{f}\in Qitalic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ∈ italic_Q is reachable in M𝑀Mitalic_M if there is γΓ𝛾superscriptΓ\gamma\in\Gamma^{*}italic_γ ∈ roman_Γ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT s.t. (s,$)M(qf,γ)superscriptsubscript𝑀𝑠currency-dollarsubscript𝑞𝑓𝛾(s,\$)\rightarrow_{M}^{*}(q_{f},\gamma)( italic_s , $ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT ( italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_γ ).

Since queue machines can deterministically encode Turing machines (see, e.g., [BravettiCZ17]), checking state reachability for queue machines is undecidable.

To prove the undecidability of fair refinement, we consider an arbitrary queue machine M𝑀Mitalic_M, and a target state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT for which we define two session types T𝑇Titalic_T and S𝑆Sitalic_S such that TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S if and only if state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M. Hereafter, we use convenient notations for denoting output selections and input branchings. Instead of using labels indexed on an indexing set I𝐼Iitalic_I, as in the input branching syntax &{li:Ti}iIsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼\&\{{l}_{i}:{T}_{i}\}_{i\in I}& { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT, we also use explicitly distinct labels, as in &{l:Tl,m:Tm}conditional-set𝑙:subscript𝑇𝑙𝑚subscript𝑇𝑚\&\{l:T_{l},m:T_{m}\}& { italic_l : italic_T start_POSTSUBSCRIPT italic_l end_POSTSUBSCRIPT , italic_m : italic_T start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } (we use the same notation for output selections). We also use the union operator to combine disjoint sets of labels, for instance, instead of writing {lk:Tk}kIJdirect-sumsubscriptconditional-setsubscript𝑙𝑘subscript𝑇𝑘𝑘𝐼𝐽\oplus\{l_{k}:T_{k}\}_{k\in I\cup J}⊕ { italic_l start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_k ∈ italic_I ∪ italic_J end_POSTSUBSCRIPT, we use the notation {li:Ti}iI{lj:Tj}jJdirect-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼subscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\oplus\{l_{i}:T_{i}\}_{i\in I}\cup\{l_{j}:T_{j}\}_{j\in J}⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT ∪ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT (we use the same notation for input branchings).

We start by defining the type T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ].222In the definition of the type T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ], as well as in the definition S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ], we make the non restrictive assumption that the set of labels \mathcal{L}caligraphic_L of the Definition 2.1 of the syntax of session types includes the symbols in the considered queue machine alphabet ΓΓ\Gammaroman_Γ plus the additional symbol E𝐸Eitalic_E. This type reproduces the finite control of the queue machine M𝑀Mitalic_M, with a couple of differences: (i𝑖iitalic_i) it initialises the queue with symbol $currency-dollar\$$, and (ii𝑖𝑖iiitalic_i italic_i) the state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT produces the additional ending symbol E𝐸Eitalic_E to communicate the end of the computation, then it consumes all symbols in the queue and successfully terminates when E𝐸Eitalic_E is read from the queue. In this way, the queue is empty when the type T𝑇Titalic_T successfully terminates.

{defi}

[Finite Control Encoding] Let M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) be a queue machine, qfQsubscript𝑞𝑓𝑄q_{f}\in Qitalic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ∈ italic_Q, and EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ be the additional ending symbol; we define [[M,qf,E]]delimited-[]𝑀subscript𝑞𝑓𝐸[\![M,q_{f},E]\!][ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] as follows:

[[M,qf,E]]={$:[[s]]}delimited-[]𝑀subscript𝑞𝑓𝐸direct-sumconditional-setcurrency-dollarsuperscriptdelimited-[]delimited-[]𝑠[\![M,q_{f},E]\!]\ =\oplus\{\$:[\![{s}]\!]^{\emptyset}\}[ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] = ⊕ { $ : [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT }

where, given qQ{qf}𝑞𝑄subscript𝑞𝑓q\in Q\setminus\{q_{f}\}italic_q ∈ italic_Q ∖ { italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT } and 𝒮Q𝒮𝑄\mathcal{S}\subseteq Qcaligraphic_S ⊆ italic_Q, [[q]]𝒮superscriptdelimited-[]delimited-[]𝑞𝒮[\![{q}]\!]^{\mathcal{S}}[ [ italic_q ] ] start_POSTSUPERSCRIPT caligraphic_S end_POSTSUPERSCRIPT is defined as follows:

[[q]]𝒮={μ𝐪.&{A:{B1A:{BnAA:[[q]]𝒮q}}}AΓif q𝒮 and δ(q,A)=(q,B1ABnAA)𝐪if q𝒮superscriptdelimited-[]delimited-[]𝑞𝒮casesformulae-sequence𝜇𝐪subscriptconditional-set𝐴direct-sumconditional-setsubscriptsuperscript𝐵𝐴1direct-sumconditional-setsubscriptsuperscript𝐵𝐴subscript𝑛𝐴superscriptdelimited-[]delimited-[]superscript𝑞𝒮𝑞𝐴Γif 𝑞𝒮 and 𝛿𝑞𝐴superscript𝑞subscriptsuperscript𝐵𝐴1subscriptsuperscript𝐵𝐴subscript𝑛𝐴missing-subexpression𝐪if q𝒮\begin{array}[]{l}[\![{q}]\!]^{\mathcal{S}}=\left\{\begin{array}[]{l}\mu% \mathbf{q}.\&\{{A}\!:\!{\oplus\{{B^{A}_{1}}:{\cdots\oplus\{{B^{A}_{n_{A}}}:{[% \![{q^{\prime}}]\!]^{\mathcal{S}\cup q}}\}}\}}\}_{A\in\Gamma}\\[2.84526pt] \hskip 25.6073pt\text{if }q\not\in{\mathcal{S}}\text{ and }\delta(q,A)=(q^{% \prime},B^{A}_{1}\cdots B^{A}_{n_{A}})\\ \\ \mathbf{q}\qquad\mbox{if $q\in{\mathcal{S}}$}\end{array}\right.\end{array}start_ARRAY start_ROW start_CELL [ [ italic_q ] ] start_POSTSUPERSCRIPT caligraphic_S end_POSTSUPERSCRIPT = { start_ARRAY start_ROW start_CELL italic_μ bold_q . & { italic_A : ⊕ { italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : ⋯ ⊕ { italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT end_POSTSUBSCRIPT : [ [ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ] start_POSTSUPERSCRIPT caligraphic_S ∪ italic_q end_POSTSUPERSCRIPT } } } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT end_CELL end_ROW start_ROW start_CELL if italic_q ∉ caligraphic_S and italic_δ ( italic_q , italic_A ) = ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT end_POSTSUBSCRIPT ) end_CELL end_ROW start_ROW start_CELL end_CELL end_ROW start_ROW start_CELL bold_q if italic_q ∈ caligraphic_S end_CELL end_ROW end_ARRAY end_CELL end_ROW end_ARRAY

while [[qf]]𝒮={E:(μ𝐭.&{A:𝐭}AΓ{E:𝐞𝐧𝐝})}[\![{q_{f}}]\!]^{\mathcal{S}}=\oplus\big{\{}E:\big{(}\mu\mathbf{\mathbf{t}}.\&% \{{A}\!:\!{\mathbf{t}}\}_{A\in\Gamma}\cup\{E:\mathbf{end}\}\big{)}\ \big{\}}[ [ italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ] ] start_POSTSUPERSCRIPT caligraphic_S end_POSTSUPERSCRIPT = ⊕ { italic_E : ( italic_μ bold_t . & { italic_A : bold_t } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : bold_end } ) }

We now define the type S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ], that repeatedly behaves like a producer/consumer for all the symbols of the queue alphabet plus the ending symbol E𝐸Eitalic_E, with the difference that after producing and consuming the ending symbol E𝐸Eitalic_E, the type becomes 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end.

{defi}

[Producer/consumer] Let M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) be a queue machine and EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ be the ending symbol. We define [[M,E]]delimited-[]𝑀𝐸[\![M,E]\!][ [ italic_M , italic_E ] ] as

[[M,E]]=μ𝐭.{A:&{A:𝐭}}AΓ{E:&{E:𝐞𝐧𝐝}}formulae-sequencedelimited-[]𝑀𝐸𝜇𝐭direct-sumsubscriptconditional-set𝐴conditional-set𝐴𝐭𝐴Γconditional-set𝐸conditional-set𝐸𝐞𝐧𝐝[\![M,E]\!]=\mu\mathbf{\mathbf{t}}.\oplus\{{A}:{\&\{A:\mathbf{t}\}}\}_{A\in% \Gamma}\cup\{E:\&\{E:\mathbf{end}\}\}[ [ italic_M , italic_E ] ] = italic_μ bold_t . ⊕ { italic_A : & { italic_A : bold_t } } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : & { italic_E : bold_end } }

While T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] and S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ] may appear unrelated, we have that under some conditions TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S holds. Namely, TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S if and only if qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M. To prove this, we first characterize the set of types that are compliant with S𝑆Sitalic_S. This set consists of types that have the same behaviour (according to type bisimilarity) of S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG, i.e., the dual of S𝑆Sitalic_S. The type S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG, instead of being a producer/consumer, is a consumer/producer which sends the messages it receives back to the partner. This simulates a FIFO queue that receives messages and sends messages in the same order of reception. Hence, the finite control encoding T𝑇Titalic_T, when combined with such consumer/producer (i.e. any type having the same behaviour of S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG), faithfully reproduces the same behaviour of the encoded queue machine. A successful configuration can be reached only if the type modeling the finite control terminates, and this is possible only if the final state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reached.

As mentioned above, the proof relies on the notion of type bisimilarity.

{defi}

[Type bisimilarity]

A relation \,\mathcal{R}\!\!\;caligraphic_R on session types is a bisimulation whenever (T,S)𝑇𝑆(T,S)\in\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R implies:

  1. (1)

    if T=𝐞𝐧𝐝𝑇𝐞𝐧𝐝T=\mathbf{end}italic_T = bold_end then 𝗎𝗇𝖿𝗈𝗅𝖽(S)=𝐞𝐧𝐝𝗎𝗇𝖿𝗈𝗅𝖽𝑆𝐞𝐧𝐝\mathsf{unfold}(S)=\mathbf{end}sansserif_unfold ( italic_S ) = bold_end;

  2. (2)

    if T={li:Ti}iI𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼T=\oplus\{{l}_{i}:{T}_{i}\}_{i\in I}italic_T = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT then 𝗎𝗇𝖿𝗈𝗅𝖽(S)={li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼{\mathsf{unfold}(S)}=\oplus\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT with iI.(Ti,Si)formulae-sequencefor-all𝑖𝐼subscript𝑇𝑖subscript𝑆𝑖\forall i\in I.\,(T_{i},S_{i})\in\mathcal{R}∀ italic_i ∈ italic_I . ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ) ∈ caligraphic_R;

  3. (3)

    if T=&{li:Ti}iI𝑇subscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼T=\&\{{l}_{i}:{T}_{i}\}_{i\in I}italic_T = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT then 𝗎𝗇𝖿𝗈𝗅𝖽(S)=&{li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆subscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼{\mathsf{unfold}(S)}=\&\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT with iI.(Ti,Si)formulae-sequencefor-all𝑖𝐼subscript𝑇𝑖subscript𝑆𝑖\forall i\in I.\,(T_{i},S_{i})\in\mathcal{R}∀ italic_i ∈ italic_I . ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ) ∈ caligraphic_R;

  4. (4)

    if T=μ𝐭.Tformulae-sequence𝑇𝜇𝐭superscript𝑇T=\mu\mathbf{t}.{T^{\prime}}italic_T = italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT then (T{T/𝐭},S)superscript𝑇𝑇𝐭𝑆(T^{\prime}\{T/\mathbf{t}\},S)\in\mathcal{R}( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT { italic_T / bold_t } , italic_S ) ∈ caligraphic_R.

T𝑇Titalic_T is bisimilar to S𝑆Sitalic_S, written TSsimilar-to𝑇𝑆T\sim Sitalic_T ∼ italic_S, if there is a bisimulation \mathcal{R}caligraphic_R such that (T,S)𝑇𝑆(T,S)\in\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R.

Session type bisimilarity will be used only in the proof of undecidability of refinement and will not be involved in further developments in the remainder of the paper. Namely, we need bisimilarity in Lemma 3 to characterise the session types that are compliant with S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ]. Notice also that the relation similar-to\sim is symmetric, i.e., if (S,T)𝑆𝑇similar-to(S,T)\in\ \sim( italic_S , italic_T ) ∈ ∼ then also (T,S)𝑇𝑆similar-to(T,S)\in\ \sim( italic_T , italic_S ) ∈ ∼. In fact, the first three items of the above Definition simply check whether the l.h.s. and the r.h.s. terms are either both 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end or have the same branching structure (i.e., the same set of labels) up-to unfolding of the r.h.s. But the same effect of unfolding on the r.h.s. can be obtained on the l.h.s. by (possibly repeated) application of the fourth item of the above definition.

In the proof of undecidability of refinement we need a result about bisimilar session types, i.e., bisimilarity preserves compliance. Namely, we have that T𝑇Titalic_T is compliant with S𝑆Sitalic_S if and only if Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is compliant with Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT assuming TTsimilar-to𝑇superscript𝑇T\sim T^{\prime}italic_T ∼ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and SSsimilar-to𝑆superscript𝑆S\sim S^{\prime}italic_S ∼ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. This is an immediate corollary of the following Lemma (which directly follows from the bisimilarity of the considered types T𝑇Titalic_T and R𝑅Ritalic_R).

Lemma 1.

Consider the configuration [T,ωT]|[S,ωS]conditional𝑇subscript𝜔𝑇𝑆subscript𝜔𝑆[T,\omega_{T}]|[S,\omega_{S}][ italic_T , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] and the session type R𝑅Ritalic_R s.t. TRsimilar-to𝑇𝑅T\sim Ritalic_T ∼ italic_R. We have that:

  • [T,ωT]|[S,ωS]conditional𝑇subscript𝜔𝑇𝑆subscript𝜔𝑆square-root[T,\omega_{T}]|[S,\omega_{S}]\surd[ italic_T , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] √ if and only if [R,ωT]|[S,ωS]conditional𝑅subscript𝜔𝑇𝑆subscript𝜔𝑆square-root[R,\omega_{T}]|[S,\omega_{S}]\surd[ italic_R , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] √;

  • [T,ωT]|[S,ωS][T,ωT]|[S,ωS]superscriptabsentconditional𝑇subscript𝜔𝑇𝑆subscript𝜔𝑆conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[T,\omega_{T}]|[S,\omega_{S}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T^{% \prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}][ italic_T , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] if and only if there exists RTsimilar-tosuperscript𝑅superscript𝑇R^{\prime}\sim T^{\prime}italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∼ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT s.t. [R,ωT]|[S,ωS][R,ωT]|[S,ωS]superscriptabsentconditional𝑅subscript𝜔𝑇𝑆subscript𝜔𝑆conditionalsuperscript𝑅superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[R,\omega_{T}]|[S,\omega_{S}]\stackrel{{\scriptstyle}}{{\rightarrow}}[R^{% \prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}][ italic_R , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ].

Corollary 2.

Consider two pairs of bisimilar session types: TTsimilar-to𝑇superscript𝑇T\sim T^{\prime}italic_T ∼ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and SSsimilar-to𝑆superscript𝑆S\sim S^{\prime}italic_S ∼ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. We have that T𝑇Titalic_T is compliant with S𝑆Sitalic_S if and only if Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is compliant with Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. Moreover, we have that TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S if and only if TSsquare-image-of-or-equalssuperscript𝑇superscript𝑆T^{\prime}\sqsubseteq S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊑ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

As informally mentioned above, type bisimilarity allows us to characterize the set of types that are compliant with a producer/consumer type S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ], for some queue machine M𝑀Mitalic_M and additional ending symbol E𝐸Eitalic_E. This result is formalized by the following Lemma (proof in Appendix A.1).

Lemma 3.

Let M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) be a queue machine and EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ the additional ending symbol. Posing S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ], for every session type Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with input/output labels in Γ{E}Γ𝐸\Gamma\cup\{E\}roman_Γ ∪ { italic_E } we have that Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is compliant with S𝑆Sitalic_S if and only if SS¯similar-tosuperscript𝑆¯𝑆S^{\prime}\sim\overline{S}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∼ over¯ start_ARG italic_S end_ARG.

The type S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG behaves like a FIFO queue, which simply returns the messages it has received from the partner (in the same order). Hence a type simulating the finite control T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ], for the same queue machine M𝑀Mitalic_M and additional ending symbol E𝐸Eitalic_E as above, turns out to be compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG if and only if the final state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M (remember that only the encoding of qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT allows to reach 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end). This result is formalized in the next theorem (proof in Appendix A.1).

Theorem 4.

Let M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) be a queue machine, qfQsubscript𝑞𝑓𝑄q_{f}\in Qitalic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ∈ italic_Q, EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ the additional ending symbol. Posing T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] and S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ], we have that T𝑇Titalic_T is compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG if and only if qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M.

Notice that the above theorem formalizes a reduction from the reachability problem in queue machines to the verification of compliance between session types. Hence, we can already conclude that the compliance relation is undecidable.

We now combine Corollary 2, Lemma 3 and Theorem 4 to prove the undecidability of refinement. Consider the two above types T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] and S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ]. By Lemma 3 we have that S𝑆Sitalic_S is compliant only with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG and its bisimilar types. Given that bisimulation preserves compliance (Corollary 2) we have that T𝑇Titalic_T refines S𝑆Sitalic_S if and only if it is compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG. But the latter holds if and only if qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M (Theorem 4). In this way we reduce the reachability problem in queue machines to the verification of refinement between session types. We formally state this result in the theorem below (proof in Appendix A.1).

Theorem 5.

Let M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) be a queue machine, qfQsubscript𝑞𝑓𝑄q_{f}\in Qitalic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ∈ italic_Q, EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ the additional ending symbol. Posing T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] and S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ], we have that TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S if and only if qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M.

As a direct consequence of the above theorem and the undecidability of reachability in queue machines, we can conclude that refinement (Definition 2.2) is also undecidable.

Corollary 6.

Given two session types T𝑇Titalic_T and S𝑆Sitalic_S, it is in general undecidable to check whether TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S holds.

2.4. Controllability and its Decidability

Given a notion of compliance, controllability amounts to checking the existence of a compliant partner (see, e.g., [Loh08, Wei08, BZ09a]). In our setting, a session type is controllable if there exists another session type with which it is compliant.

Checking for controllability algorithmically is not trivial as it requires to consider infinitely many potential partners. For the synchronous case, an algorithmic characterisation was studied in [Padovani16]. In the asynchronous case, the problem is even harder because each of the infinitely many potential partners may generate an infinite state computation (due to unbounded buffers): specifically this reflects in the proof of its algorithmic characterisation. The main contribution of this subsection is, thus, to give an algorithmic characterisation of controllability in the asynchronous setting that is proven to be sound and complete. Doing this is important because controllability is an essential ingredient for defining fair asynchronous subtyping, see Section 3.

001111222233334444?l1?subscript𝑙1?\mathit{l_{1}}? italic_l start_POSTSUBSCRIPT italic_1 end_POSTSUBSCRIPT?l3?subscript𝑙3?\mathit{l_{3}}? italic_l start_POSTSUBSCRIPT italic_3 end_POSTSUBSCRIPT?l2?subscript𝑙2?\mathit{l_{2}}? italic_l start_POSTSUBSCRIPT italic_2 end_POSTSUBSCRIPT!l4!{\mathit{l_{4}}}! italic_l start_POSTSUBSCRIPT italic_4 end_POSTSUBSCRIPT!l5!{\mathit{l_{5}}}! italic_l start_POSTSUBSCRIPT italic_5 end_POSTSUBSCRIPT!l6!{\mathit{l_{6}}}! italic_l start_POSTSUBSCRIPT italic_6 end_POSTSUBSCRIPT
Figure 2. Example of an uncontrollable session type, see Example 2.4.
{defi}

[Characterisation of Controllability, T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl] We preliminarly define judgement T𝗈𝗄𝑇𝗈𝗄T\,\mathsf{ok}italic_T sansserif_ok for session types T𝑇Titalic_T having single input choices, i.e. such that all their input branches include just one possible choice. T𝗈𝗄𝑇𝗈𝗄T\,\mathsf{ok}italic_T sansserif_ok is defined inductively as follows: {mathpar} \inferruleendok

\inferrule

end∈T T{𝐞𝐧𝐝/𝐭𝐞𝐧𝐝𝐭\nicefrac{{\mathbf{end}}}{{\mathbf{t}}}/ start_ARG bold_end end_ARG start_ARG bold_t end_ARG}  ok μt.T  ok

\inferrule

T ok &{l:T}  ok

\inferrule

∀i ∈I . T_i  ok ⊕{l_i:T_i}_i∈I  ok where 𝐞𝐧𝐝T𝐞𝐧𝐝𝑇\mathbf{end}\in Tbold_end ∈ italic_T holds if 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end occurs in T𝑇Titalic_T.

We now define predicate T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl over arbitrary session types T𝑇Titalic_T as follows. T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl holds true if and only if there exists Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that:

  1. (1)

    Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is obtained from T𝑇Titalic_T by syntactically replacing every input choice &{li:Ti}iIsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼\&\{{l}_{i}:{T}_{i}\}_{i\in I}& { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT occurring in T𝑇Titalic_T with a term &{lj:Tj}conditional-setsubscript𝑙𝑗subscriptsuperscript𝑇𝑗\&\{{l_{j}}:{T^{\prime}_{j}}\}& { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } (with jI𝑗𝐼j\in Iitalic_j ∈ italic_I). Formally this is denoted by T𝗌𝗂𝗇T𝑇𝗌𝗂𝗇superscript𝑇T\;\mathsf{sin}\;T^{\prime}italic_T sansserif_sin italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, where 𝗌𝗂𝗇𝗌𝗂𝗇\mathsf{sin}sansserif_sin (standing for “single input choices”) is defined as the smallest relation over session types such that: {mathpar} \inferruleendsinend

    \inferrule

    tsint

    \inferrule

    T   sin   T’ μt.T   sinμt.T’

    \inferrule

    T_j   sin   T’_j j ∈I &{l_i:T_i}_i∈I   sin   &{l_j:T’_j}

    \inferrule

    ∀i ∈I . T_i   sin   T’_i ⊕{l_i:T_i}_i∈I   sin   ⊕{l_i:T’​​_i}_i∈I In the following we use 𝗌𝗂𝗇(T)𝗌𝗂𝗇𝑇\mathsf{sin}(T)sansserif_sin ( italic_T ) to denote the set of single input choice types Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that T𝗌𝗂𝗇T𝑇𝗌𝗂𝗇superscript𝑇T\;\mathsf{sin}\;T^{\prime}italic_T sansserif_sin italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

  2. (2)

    T𝗈𝗄superscript𝑇𝗈𝗄T^{\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT sansserif_ok holds true.

A type T𝑇Titalic_T such that T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl is indeed controllable, in that T¯¯superscript𝑇\overline{T^{\prime}}over¯ start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_ARG, the dual of type Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT considered above, is compliant with T𝑇Titalic_T (the predicate 𝐞𝐧𝐝T𝐞𝐧𝐝𝑇\mathbf{end}\!\in\!Tbold_end ∈ italic_T in the premise of the rule for recursion guarantees that a successful configuration is always reachable while looping). Moreover the above definition naturally yields a simple algorithm that decides whether or not T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl holds for a type T𝑇Titalic_T, i.e., we first pick a single branch for each input prefix syntactically occurring in T𝑇Titalic_T (there are finitely many of them) and then we inductively check if T𝗈𝗄superscript𝑇𝗈𝗄T^{\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT sansserif_ok holds.

{exa}

Consider the session type T𝑇Titalic_T (see Figure 2 for a graphical representation):

T=μ𝐭.&{l1:&{l2:{l4:𝐞𝐧𝐝,l5:μ𝐭.{l6:𝐭}},l3:𝐭}}T=\mu\mathbf{t}.~{}\&\{l_{1}:\&\{l_{2}:\oplus\{l_{4}:\mathbf{end},\ l_{5}:\mu% \mathbf{t^{\prime}}.\oplus\{l_{6}:\mathbf{t^{\prime}}\}\},\ l_{3}:\mathbf{t}\}\}italic_T = italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : & { italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 4 end_POSTSUBSCRIPT : bold_end , italic_l start_POSTSUBSCRIPT 5 end_POSTSUBSCRIPT : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . ⊕ { italic_l start_POSTSUBSCRIPT 6 end_POSTSUBSCRIPT : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } } , italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_t } }

T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl does not hold because it is not possible to construct a Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT as specified in Definition 2 for which T𝗈𝗄superscript𝑇𝗈𝗄T^{\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT sansserif_ok holds. In this case we have just two possible types Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT that can be obtained by input choice replacement: T=μ𝐭.&{l1:&{l3:𝐭}}formulae-sequencesuperscript𝑇𝜇𝐭conditional-setsubscript𝑙1conditional-setsubscript𝑙3𝐭T^{\prime}=\mu\mathbf{t}.~{}\&\{l_{1}:\&\{l_{3}:\mathbf{t}\}\}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : & { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_t } } and T=μ𝐭.&{l1:&{l2:{l4:𝐞𝐧𝐝,l5:μ𝐭.{l6:𝐭}}}}T^{\prime}=\mu\mathbf{t}.~{}\&\{l_{1}:\&\{l_{2}:\oplus\{l_{4}:\mathbf{end},\ l% _{5}:\mu\mathbf{t^{\prime}}.\oplus\{l_{6}:\mathbf{t^{\prime}}\}\}\}\}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : & { italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 4 end_POSTSUBSCRIPT : bold_end , italic_l start_POSTSUBSCRIPT 5 end_POSTSUBSCRIPT : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . ⊕ { italic_l start_POSTSUBSCRIPT 6 end_POSTSUBSCRIPT : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } } } }. For the former T𝗈𝗄superscript𝑇𝗈𝗄T^{\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT sansserif_ok does not hold because there is no 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end in the body of μ𝐭𝜇𝐭\mu\mathbf{t}italic_μ bold_t; for the latter, instead, T𝗈𝗄superscript𝑇𝗈𝗄T^{\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT sansserif_ok does not hold because there is no 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end in the body of μ𝐭𝜇superscript𝐭\mu\mathbf{t^{\prime}}italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

As a result of Theorem 7 (below), there is no session type S𝑆Sitalic_S that is compliant with T𝑇Titalic_T. Hence T𝑇Titalic_T is not controllable.

The following theorem shows that the judgement T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl, as defined above, precisely characterises controllability (i.e., the existence of a compliant type). Its proof is rather complex (it requires introducing significant auxiliary technical machinery) and can be found in Appendix A.2.

Theorem 7.

T𝖼𝗍𝗋𝗅𝑇𝖼𝗍𝗋𝗅T\,\mathsf{ctrl}italic_T sansserif_ctrl holds if and only if there exists a session type S𝑆Sitalic_S such that T𝑇Titalic_T and S𝑆Sitalic_S are compliant.

Sketch of the proof. The proof relies on expressing session types via a set of equations, where each of the variables 𝐭𝐭\mathbf{t}bold_t is mapped to an equation. In essence, from T𝑇Titalic_T controllable we show that there exists a compliant type by considering the type T¯¯superscript𝑇\overline{T^{\prime}}over¯ start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_ARG (in equation set notation), where Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is the type with single input branches obtained from T𝑇Titalic_T by input choice replacement. The more difficult part of the proof is the opposite implication, where from the existence of any compliant S𝑆Sitalic_S we show that T𝑇Titalic_T is controllable. This amounts to show that it is possible to build Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT from the transition system of the correct composition [T,ϵ]|[S,ϵ]conditional𝑇italic-ϵ𝑆italic-ϵ[T,\epsilon]|[S,\epsilon][ italic_T , italic_ϵ ] | [ italic_S , italic_ϵ ] (in equation set notation), which is, in general, infinite state. ∎

3. Fair Asynchronous Session Subtyping

In this section, we present our novel variant of asynchronous subtyping which we call fair asynchronous subtyping.

First, we need to define a distinctive notion of unfolding. As anticipated in the introduction (see the discussion about Figure 1), our subtyping will identify the type TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT as a subtype of TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT, with

TG=μ𝐭.&{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:μ𝐭.{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}}T_{G}\ =\ \mu\mathbf{t}.~{}\&\{\mathit{tm}:\mathbf{t},\mathit{over}:\mu\mathbf% {t^{\prime}}.\oplus\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:\mathbf{end% }\}\}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT = italic_μ bold_t . & { italic_tm : bold_t , italic_over : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . ⊕ { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } }

Following the approach taken in other definitions of asynchronous subtyping [MY15, MariangiolaPreciness, CDY2014], our definition will require to decompose the candidate supertype (TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT in our case) as an input context, with holes filled with subtypes starting with output selections. Notice that the subterm {𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}direct-sumconditional-set𝑡𝑐:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝\oplus\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:\mathbf{end}\}⊕ { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } of TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT which starts with an output selection is not a correct subtype because it contains the free occurrence of the recursive variable 𝐭superscript𝐭\mathbf{t^{\prime}}bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. Our distinctive notion of unfolding, will replace such free variable with its definition. More precisely, we define the function 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(T)𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑇\mathsf{selUnfold}(T)sansserif_selUnfold ( italic_T ) to unfold type T𝑇Titalic_T by replacing recursion variables with their corresponding definitions only if they are guarded by an output selection. In the definition, we use the predicate g(𝐭,T)direct-sum𝑔𝐭𝑇\oplus\mathit{g}(\mathbf{t},T)⊕ italic_g ( bold_t , italic_T ) which holds if all instances of variable 𝐭𝐭\mathbf{t}bold_t are output selection guarded, i.e., 𝐭𝐭\mathbf{t}bold_t occurs free in T𝑇Titalic_T only inside subterms {li:Ti}iIdirect-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼{\oplus\{{l}_{i}:{T}_{i}\}_{i\in I}}⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT.

{defi}

[Selective Unfolding] Given a term T𝑇Titalic_T, we define 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(T)=𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑇absent\mathsf{selUnfold}(T)=sansserif_selUnfold ( italic_T ) =

{{li:Ti}iIif T={li:Ti}iI&{li:𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(Ti)}iIif T=&{li:Ti}iIT{μ𝐭.T/𝐭}if T=μ𝐭.Tg(𝐭,T)μ𝐭.𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(𝗌𝖾𝗅𝖱𝖾𝗉𝗅(𝐭,𝐭^,T){μ𝐭.T/𝐭^})𝑤𝑖𝑡ℎ𝐭^𝑓𝑟𝑒𝑠ℎif T=μ𝐭.T¬g(𝐭,T)𝐭if T=𝐭𝐞𝐧𝐝if T=𝐞𝐧𝐝casesdirect-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼if 𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼subscriptconditional-setsubscript𝑙𝑖𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽subscript𝑇𝑖𝑖𝐼if 𝑇subscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼superscript𝑇formulae-sequence𝜇𝐭superscript𝑇𝐭formulae-sequenceif 𝑇𝜇𝐭superscript𝑇g(𝐭,T)formulae-sequence𝜇𝐭𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝗌𝖾𝗅𝖱𝖾𝗉𝗅𝐭^𝐭superscript𝑇formulae-sequence𝜇𝐭superscript𝑇^𝐭𝑤𝑖𝑡ℎ^𝐭𝑓𝑟𝑒𝑠ℎformulae-sequenceif 𝑇𝜇𝐭superscript𝑇¬g(𝐭,T)𝐭if 𝑇𝐭𝐞𝐧𝐝if 𝑇𝐞𝐧𝐝\begin{cases}\oplus\{{l}_{i}:{T}_{i}\}_{i\in I}&\text{if }T={\oplus\{{l}_{i}:{% T}_{i}\}_{i\in I}}\\ \&\{l_{i}:\mathsf{selUnfold}(T_{i})\}_{i\in I}&\text{if }T={\&\{{l}_{i}:{T}_{i% }\}_{i\in I}}\\ T^{\prime}\{\nicefrac{{\mu\mathbf{t}.T^{\prime}}}{{\mathbf{t}}}\}&\text{if }T=% {\mu\mathbf{t}.T^{\prime}}\text{, $\oplus\mathit{g}(\mathbf{t},T^{\prime})$}\\ \mu\mathbf{t}.\mathsf{selUnfold}(\mathsf{selRepl}(\mathbf{t},\mathbf{\hat{t}},% T^{\prime})\{\nicefrac{{\mu\mathbf{t}.T^{\prime}}}{{\mathbf{\hat{t}}}}\})\ % \mathit{with}\ \mathbf{\hat{t}}\ \mathit{fresh}&\text{if }T={\mu\mathbf{t}.T^{% \prime}}\text{, $\lnot\oplus\mathit{g}(\mathbf{t},T^{\prime})$}\\ \mathbf{t}&\text{if }T={\mathbf{t}}\\ \mathbf{end}&\text{if }T={\mathbf{end}}\end{cases}{ start_ROW start_CELL ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT end_CELL start_CELL if italic_T = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT end_CELL end_ROW start_ROW start_CELL & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : sansserif_selUnfold ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ) } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT end_CELL start_CELL if italic_T = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT end_CELL end_ROW start_ROW start_CELL italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT { / start_ARG italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_ARG start_ARG bold_t end_ARG } end_CELL start_CELL if italic_T = italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , ⊕ italic_g ( bold_t , italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) end_CELL end_ROW start_ROW start_CELL italic_μ bold_t . sansserif_selUnfold ( sansserif_selRepl ( bold_t , over^ start_ARG bold_t end_ARG , italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) { / start_ARG italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_ARG start_ARG over^ start_ARG bold_t end_ARG end_ARG } ) italic_with over^ start_ARG bold_t end_ARG italic_fresh end_CELL start_CELL if italic_T = italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , ¬ ⊕ italic_g ( bold_t , italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) end_CELL end_ROW start_ROW start_CELL bold_t end_CELL start_CELL if italic_T = bold_t end_CELL end_ROW start_ROW start_CELL bold_end end_CELL start_CELL if italic_T = bold_end end_CELL end_ROW

where, 𝗌𝖾𝗅𝖱𝖾𝗉𝗅(𝐭,𝐭^,T)𝗌𝖾𝗅𝖱𝖾𝗉𝗅𝐭^𝐭superscript𝑇\mathsf{selRepl}(\mathbf{t},\mathbf{\hat{t}},T^{\prime})sansserif_selRepl ( bold_t , over^ start_ARG bold_t end_ARG , italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) is obtained from Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT by replacing the free occurrences of 𝐭𝐭\mathbf{t}bold_t that are inside a subterm {li:Si}iIdirect-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼\oplus\{{l}_{i}:{S}_{i}\}_{i\in I}⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT of Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT by 𝐭^^𝐭\mathbf{\hat{t}}over^ start_ARG bold_t end_ARG.

{exa}

Consider the type T=μ𝐭.&{l1:𝐭,l2:{l3:𝐭}}formulae-sequence𝑇𝜇𝐭conditional-setsubscript𝑙1:𝐭subscript𝑙2direct-sumconditional-setsubscript𝑙3𝐭T=\mu\mathbf{t}.\&\{l_{1}:\mathbf{t},\,l_{2}:\oplus\{l_{3}:\mathbf{t}\}\}italic_T = italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_t } }, then we have

𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(T)=μ𝐭.&{l1:𝐭,l2:{l3:μ𝐭.&{l1:𝐭,l2:{l3:𝐭}}}}formulae-sequence𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑇𝜇𝐭conditional-setsubscript𝑙1:𝐭subscript𝑙2direct-sumconditional-setsubscript𝑙3formulae-sequence𝜇𝐭conditional-setsubscript𝑙1:𝐭subscript𝑙2direct-sumconditional-setsubscript𝑙3𝐭\mathsf{selUnfold}(T)=\mu\mathbf{t}.\&\{l_{1}:\mathbf{t},\,l_{2}:\oplus\{l_{3}% :\mu\mathbf{t}.~{}\&\{l_{1}:\mathbf{t},\,l_{2}:\oplus\{l_{3}:\mathbf{t}\}\}\}\}sansserif_selUnfold ( italic_T ) = italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : italic_μ bold_t . & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_t } } } }

i.e., the type is only unfolded within output selection sub-terms. Note that 𝐭^^𝐭\mathbf{\hat{t}}over^ start_ARG bold_t end_ARG is used to identify where unfolding must take place, e.g.,
𝗌𝖾𝗅𝖱𝖾𝗉𝗅(𝐭,𝐭^,&{l1:𝐭,l2:{l3:𝐭}})=&{l1:𝐭,l2:{l3:𝐭^}}𝗌𝖾𝗅𝖱𝖾𝗉𝗅𝐭^𝐭conditional-setsubscript𝑙1:𝐭subscript𝑙2direct-sumconditional-setsubscript𝑙3𝐭conditional-setsubscript𝑙1:𝐭subscript𝑙2direct-sumconditional-setsubscript𝑙3^𝐭\mathsf{selRepl}(\mathbf{t},\mathbf{\hat{t}},\&\{l_{1}:\mathbf{t},\,l_{2}:% \oplus\{l_{3}:\mathbf{t}\}\})={\&\{l_{1}:\mathbf{t},\,l_{2}:\oplus\{l_{3}:% \mathbf{\hat{t}}\}\}}sansserif_selRepl ( bold_t , over^ start_ARG bold_t end_ARG , & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_t } } ) = & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_t , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : over^ start_ARG bold_t end_ARG } }.

The last auxiliary notation required to define our notion of subtyping is that of input contexts, which are used to record inputs that may be delayed in a candidate super-type. In contrast to previous works on asynchronous subtyping, these input contexts may include recursive constructs. {defi}[Input Context] An input context 𝒜𝒜\mathcal{A}caligraphic_A is a session type with several holes defined by the syntax:

𝒜::=[]k&{li:𝒜i}iIμ𝐭.𝒜𝐭\mathcal{A}\ ::=\ \quad[\,]^{k}\quad\mid\qquad\&\{{l}_{i}:{\mathcal{A}}_{i}\}_% {i\in I}\quad\mid\qquad\mu\mathbf{t}.{\mathcal{A}}\quad\mid\qquad\mathbf{t}caligraphic_A : := [ ] start_POSTSUPERSCRIPT italic_k end_POSTSUPERSCRIPT ∣ & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : caligraphic_A start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT ∣ italic_μ bold_t . caligraphic_A ∣ bold_t

where the holes []ksuperscript𝑘[\,]^{k}[ ] start_POSTSUPERSCRIPT italic_k end_POSTSUPERSCRIPT, with kK𝑘𝐾k\in Kitalic_k ∈ italic_K, of an input context 𝒜𝒜\mathcal{A}caligraphic_A are assumed to be pairwise distinct. We assume that recursion is guarded, i.e., in an input context μ𝐭.𝒜formulae-sequence𝜇𝐭𝒜\mu\mathbf{t}.{\mathcal{A}}italic_μ bold_t . caligraphic_A, the recursion variable 𝐭𝐭\mathbf{t}bold_t must occur within a subterm &{li:𝒜i}iIsubscriptconditional-setsubscript𝑙𝑖subscript𝒜𝑖𝑖𝐼\&\{{l}_{i}:{\mathcal{A}}_{i}\}_{i\in I}& { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : caligraphic_A start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT.

We write ℎ𝑜𝑙𝑒𝑠(𝒜)ℎ𝑜𝑙𝑒𝑠𝒜\mathit{holes}(\mathcal{A})italic_holes ( caligraphic_A ) for the set of hole indices in 𝒜𝒜\mathcal{A}caligraphic_A. Given a type Tksubscript𝑇𝑘T_{k}italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT for each kK𝑘𝐾k\in Kitalic_k ∈ italic_K, we write 𝒜[Tk]kK𝒜superscriptdelimited-[]subscript𝑇𝑘𝑘𝐾\mathcal{A}[{T_{k}}]^{k\in K}caligraphic_A [ italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT for the type obtained by filling each hole k𝑘kitalic_k in 𝒜𝒜\mathcal{A}caligraphic_A with the corresponding Tksubscript𝑇𝑘T_{k}italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT.

In contrast to previous works [MariangiolaPreciness, ESOP09, CDY2014, BravettiCZ17, sefm19, BCLYZ19], these input contexts may contain recursive constructs. This is crucial to deal with examples such as Figure 1.

We are now ready to define the fair asynchronous subtyping relation, written \operatorname{\leq}. The rationale behind asynchronous session subtyping is that under asynchronous communication it is unobservable whether or not an output is anticipated before an input, as long as this output is executed along all branches of the candidate super-type. Besides the usage of our new recursive input contexts the definition of fair asynchronous subtyping differs from those in [MariangiolaPreciness, ESOP09, CDY2014, BravettiCZ17, sefm19, BCLYZ19] in that controllability plays a fundamental role: the subtype is not required to mimic supertype inputs leading to uncontrollable behaviours.

{defi}

[Fair Asynchronous Subtyping, \operatorname{\leq}]

A relation \,\mathcal{R}\!\!\;caligraphic_R on session types is a controllable subtyping relation whenever

(T,S)𝑇𝑆(T,S)\in\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R implies:

  1. (1)

    if T=𝐞𝐧𝐝𝑇𝐞𝐧𝐝T=\mathbf{end}italic_T = bold_end then 𝗎𝗇𝖿𝗈𝗅𝖽(S)=𝐞𝐧𝐝𝗎𝗇𝖿𝗈𝗅𝖽𝑆𝐞𝐧𝐝\mathsf{unfold}(S)=\mathbf{end}sansserif_unfold ( italic_S ) = bold_end;

  2. (2)

    if T=μ𝐭.Tformulae-sequence𝑇𝜇𝐭superscript𝑇T=\mu\mathbf{t}.{T^{\prime}}italic_T = italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT then (T{T/𝐭},S)superscript𝑇𝑇𝐭𝑆(T^{\prime}\{\nicefrac{{T}}{{\mathbf{t}}}\},S)\in\mathcal{R}( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT { / start_ARG italic_T end_ARG start_ARG bold_t end_ARG } , italic_S ) ∈ caligraphic_R;

  3. (3)

    if T=&{li:Ti}iI𝑇subscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼T=\&\{{l}_{i}:{T}_{i}\}_{i\in I}italic_T = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT then 𝗎𝗇𝖿𝗈𝗅𝖽(S)=&{lj:Sj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑆subscriptconditional-setsubscript𝑙𝑗subscript𝑆𝑗𝑗𝐽\mathsf{unfold}(S)=\&\{{l}_{j}:{S}_{j}\}_{j\in J}sansserif_unfold ( italic_S ) = & { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT, IK𝐾𝐼I\supseteq Kitalic_I ⊇ italic_K, and kK.(Tk,Sk)for-all𝑘.𝐾subscript𝑇𝑘subscript𝑆𝑘\forall k\in K\ldotp(T_{k},S_{k})\in\mathcal{R}∀ italic_k ∈ italic_K . ( italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT , italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ) ∈ caligraphic_R, where K={kJ|Sk is controllable}𝐾conditional-set𝑘𝐽subscript𝑆𝑘 is controllableK=\{k\in J\;|\;S_{k}\text{ is controllable}\}italic_K = { italic_k ∈ italic_J | italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT is controllable };

  4. (4)

    if T={li:Ti}iI𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼T=\oplus\{{l}_{i}:{T}_{i}\}_{i\in I}italic_T = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT then 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(S)=𝒜[{li:Ski}iI]kK𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑆𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑖subscriptsubscript𝑆𝑘𝑖𝑖𝐼𝑘𝐾\mathsf{selUnfold}(S)\!=\!\mathcal{A}[{\oplus\{{l}_{i}\!:\!{S_{k}}_{i}\}_{i\in I% }}]^{k\in K}sansserif_selUnfold ( italic_S ) = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT and iI.(Ti,𝒜[Ski]kK)formulae-sequencefor-all𝑖𝐼subscript𝑇𝑖𝒜superscriptdelimited-[]subscript𝑆𝑘𝑖𝑘𝐾\forall i\!\in\!I.\,(T_{i},\mathcal{A}[{{S_{ki}}}]^{k\in K})\!\in\!\mathcal{R}∀ italic_i ∈ italic_I . ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) ∈ caligraphic_R.

T𝑇Titalic_T is a controllable subtype of S𝑆Sitalic_S if there is a controllable subtyping relation \mathcal{R}caligraphic_R s.t. (T,S)𝑇𝑆(T,S)\,\in\,\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R.

T𝑇Titalic_T is a fair asynchronous subtype of S𝑆Sitalic_S, written TS𝑇𝑆T\,\operatorname{\leq}\,Sitalic_T ≤ italic_S, whenever: S𝑆Sitalic_S controllable implies that T𝑇Titalic_T is a controllable subtype of S𝑆Sitalic_S. Notice that the top-level check for controllability in the above definition is consistent with the inner controllability checks performed in Case (3)3(3)( 3 ).

Subtyping simulation game

Session type T𝑇Titalic_T is a fair asynchronous subtype of S𝑆Sitalic_S if S𝑆Sitalic_S is not controllable or if T𝑇Titalic_T is a controllable subtype of S𝑆Sitalic_S. Intuitively, the above co-inductive definition says that it is possible to play a simulation game between a subtype T𝑇Titalic_T and its supertype S𝑆Sitalic_S as follows. Case (1) says that if T𝑇Titalic_T is the 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end type, then S𝑆Sitalic_S must also be 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end. Case (2) says that if T𝑇Titalic_T is recursively defined, then T𝑇Titalic_T is replaced by the unfolding of its definition, S𝑆Sitalic_S is left unchanged and the simulation game continues. Case (3) says that if T𝑇Titalic_T is an input branching, then the sub-terms in S𝑆Sitalic_S that are controllable can reply by inputting at most some of the labels lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT in the branching (contravariance of inputs), and the simulation game continues (see Example 3). Case (4) says that if T𝑇Titalic_T is an output selection, then S𝑆Sitalic_S can reply by outputting all the labels lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT in the selection, possibly after executing some inputs, after which the simulation game continues. We comment further on Case (4) with Example 3.

{exa}

Consider T=&{l1:𝐞𝐧𝐝,l2:𝐞𝐧𝐝}𝑇conditional-setsubscript𝑙1:𝐞𝐧𝐝subscript𝑙2𝐞𝐧𝐝T=\&\{l_{1}:\mathbf{end},\ l_{2}:\mathbf{end}\}italic_T = & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_end , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : bold_end } and S=&{l1:𝐞𝐧𝐝,l3:μ𝐭.{l4:𝐭}}S=\&\{l_{1}:\mathbf{end},\ l_{3}:\mu\mathbf{t}.\oplus\{l_{4}:\mathbf{t}\}\}italic_S = & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_end , italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : italic_μ bold_t . ⊕ { italic_l start_POSTSUBSCRIPT 4 end_POSTSUBSCRIPT : bold_t } }. We have TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. Once branch l3subscript𝑙3l_{3}italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT, that is uncontrollable, is removed from S𝑆Sitalic_S, we can apply contravariance for input branching. We have I={1,2}{1}=K𝐼12superset-of-or-equals1𝐾I=\{1,2\}\supseteq\{1\}=Kitalic_I = { 1 , 2 } ⊇ { 1 } = italic_K in Definition 3.

{exa}

Consider TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT and TGsubscriptsuperscript𝑇𝐺T^{\prime}_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT from Figure 1. For the pair (TG,TG)subscriptsuperscript𝑇𝐺subscript𝑇𝐺(T^{\prime}_{G},T_{G})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT , italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT ), we apply Case (4) of Definition 3 for which we compute

𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(TG)=𝒜[{𝑡𝑐:μ𝐭.{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝},𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}]\mathsf{selUnfold}(T_{G})=\mathcal{A}[\oplus\{\mathit{tc}:\mu\mathbf{t^{\prime% }}.\oplus\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:\mathbf{end}\},% \mathit{done}:\mathbf{end}\}]sansserif_selUnfold ( italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT ) = caligraphic_A [ ⊕ { italic_tc : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . ⊕ { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } , italic_done : bold_end } ]

with 𝒜=μ𝐭.&{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:[]1}formulae-sequence𝒜𝜇𝐭conditional-set𝑡𝑚:𝐭𝑜𝑣𝑒𝑟superscript1\mathcal{A}=\mu\mathbf{t}.\&\{\mathit{tm}:\mathbf{t},\mathit{over}:[\,]^{1}\}caligraphic_A = italic_μ bold_t . & { italic_tm : bold_t , italic_over : [ ] start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT }. Observe that 𝒜𝒜\mathcal{A}caligraphic_A contains a recursive sub-term, such contexts are not allowed in previous works [MariangiolaPreciness, ESOP09, CDY2014].

The use of selective unfolding makes it possible to express TGsubscript𝑇𝐺T_{G}italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT in terms of a recursive input context 𝒜𝒜\mathcal{A}caligraphic_A with holes filled by types (i.e., closed terms) that start with an output prefix. Indeed selective unfolding does not unfold the recursion variable 𝐭𝐭\mathbf{t}bold_t (not guarded by an output selection), which becomes part of the input context 𝒜𝒜\mathcal{A}caligraphic_A. Instead it unfolds the recursion variable 𝐭superscript𝐭\mathbf{t}^{\prime}bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT (which is guarded by an output selection) so that the term that fills the hole, which is required to start with an output prefix, is a closed term.

Case (4) of Definition 3 requires us to check that the following pairs are in the relation: (i𝑖iitalic_i) (TG,𝒜[μ𝐭.{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}])(T^{\prime}_{G},\mathcal{A}[\mu\mathbf{t^{\prime}}.\oplus\{\mathit{tc}:\mathbf% {t^{\prime}},\mathit{done}:\mathbf{end}\}])( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT , caligraphic_A [ italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . ⊕ { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } ] ) and (ii𝑖𝑖iiitalic_i italic_i) (μ𝐭.&{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝},𝒜[𝐞𝐧𝐝])formulae-sequence𝜇superscript𝐭conditional-set𝑡𝑚:superscript𝐭𝑜𝑣𝑒𝑟𝐞𝐧𝐝𝒜delimited-[]𝐞𝐧𝐝(\mu\mathbf{t^{\prime}}.~{}\&\{\mathit{tm}:\mathbf{t^{\prime}},\mathit{over}:% \mathbf{end}\},\mathcal{A}[\mathbf{end}])( italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tm : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_over : bold_end } , caligraphic_A [ bold_end ] ). Observe that TG=𝒜[μ𝐭.{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}]T_{G}=\mathcal{A}[\mu\mathbf{t^{\prime}}.\oplus\{\mathit{tc}:\mathbf{t^{\prime% }},\mathit{done}:\mathbf{end}\}]italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT = caligraphic_A [ italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . ⊕ { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } ]. Hence, we have TGTGsubscriptsuperscript𝑇𝐺subscript𝑇𝐺T^{\prime}_{G}\leq T_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT ≤ italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT with

={(TG,TG),(𝐞𝐧𝐝,𝐞𝐧𝐝),(μ𝐭.&{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝},μ𝐭.&{𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝})}\mathcal{R}\!=\!\left\{(T^{\prime}_{G},T_{G}),(\mathbf{end},\mathbf{end}),(\mu% \mathbf{t^{\prime}}.\&\{\mathit{tm}\!:\mathbf{t^{\prime}},\mathit{over}\!:% \mathbf{end}\},\mu\mathbf{t}.\&\{\mathit{tm}\!:\mathbf{t},\mathit{over}\!:% \mathbf{end}\})\right\}caligraphic_R = { ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT , italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT ) , ( bold_end , bold_end ) , ( italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tm : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_over : bold_end } , italic_μ bold_t . & { italic_tm : bold_t , italic_over : bold_end } ) }

and \mathcal{R}caligraphic_R is a controllable subtyping relation.

We show that fair asynchronous subtyping is sound w.r.t. fair refinement. In fact, fair asynchronous subtyping can be seen as a sound coinductive characterisation of fair refinement. Namely this result gives an operational justification to the syntactical definition of fair asynchronous session subtyping. Note that \operatorname{\leq} is not complete w.r.t. square-image-of-or-equals\sqsubseteq, see Example 3.

The proof of soundness of fair asynchronous subtyping w.r.t. fair refinement is rather complex and can be found in Appendix A.3, here we report the two main results and a sketch of their proofs.

Proposition 8.

Given two session types T𝑇Titalic_T and S𝑆Sitalic_S, if TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S then, for every ω𝜔\omegaitalic_ω, R𝑅Ritalic_R, and ωRsubscript𝜔𝑅\omega_{R}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT such that [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition, there exist Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, ωsuperscript𝜔\omega^{\prime}italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, Rsuperscript𝑅R^{\prime}italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, and ωRsuperscriptsubscript𝜔𝑅\omega_{R}^{\prime}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that [T,ω]|[R,ωR][T,ω]|[R,ωR]superscriptsuperscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[T^{% \prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] and [T,ω]|[R,ωR]conditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅square-root[T^{\prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}]\surd[ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] √.

Sketch of the proof. Given that [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition, there exist Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, ω′′superscript𝜔′′\omega^{\prime\prime}italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, R′′superscript𝑅′′R^{\prime\prime}italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, and ωR′′superscriptsubscript𝜔𝑅′′\omega_{R}^{\prime\prime}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that [S,ω]|[R,ωR][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[S^{% \prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] and [S,ω]|[R′′,ωR′′]conditionalsuperscript𝑆superscript𝜔superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[S^{\prime},\omega^{\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}]\surd[ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √. The thesis is proved by induction on the length of this sequence of transitions.

If the length is 0, then [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅square-root[S,\omega]|[R,\omega_{R}]\surd[ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] √, that implies 𝗎𝗇𝖿𝗈𝗅𝖽(S)=𝐞𝐧𝐝𝗎𝗇𝖿𝗈𝗅𝖽𝑆𝐞𝐧𝐝\mathsf{unfold}(S)=\mathbf{end}sansserif_unfold ( italic_S ) = bold_end, that also implies 𝗎𝗇𝖿𝗈𝗅𝖽(T)=𝐞𝐧𝐝𝗎𝗇𝖿𝗈𝗅𝖽𝑇𝐞𝐧𝐝\mathsf{unfold}(T)=\mathbf{end}sansserif_unfold ( italic_T ) = bold_end (because TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S), from which we have [T,ω]|[R,ωR]conditional𝑇𝜔𝑅subscript𝜔𝑅square-root[T,\omega]|[R,\omega_{R}]\surd[ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] √.

If the length is greater than 0, we proceed by case analysis on the first possible transition [S,ω]|[R,ωR][S′′,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑆′′superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[S^{\prime% \prime},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{% \prime\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ].

If the transition is inferred by R𝑅Ritalic_R it is sufficient to observe that S′′=Ssuperscript𝑆′′𝑆S^{\prime\prime}=Sitalic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT = italic_S and [T,ω]|[R,ωR][T,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditional𝑇superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T,\omega^{% \prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ], and then apply the inductive hypothesis because [S′′,ω′′′]|[R′′′,ωR′′′]conditionalsuperscript𝑆′′superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S^{\prime\prime},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_% {R}^{\prime\prime\prime}][ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] is a correct composition in that it is reachable from a correct composition.

We now consider that the transition is inferred by S𝑆Sitalic_S.
There are three possible cases:

  1. (1)

    𝗎𝗇𝖿𝗈𝗅𝖽(S)={li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼\mathsf{unfold}(S)=\oplus\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT,

  2. (2)

    𝗎𝗇𝖿𝗈𝗅𝖽(S)=&{li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆subscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼\mathsf{unfold}(S)=\&\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT and T𝑇Titalic_T starts with an input branching (i.e., 𝗎𝗇𝖿𝗈𝗅𝖽(T)=&{lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇subscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\&\{l_{j}:T_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = & { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT),

  3. (3)

    𝗎𝗇𝖿𝗈𝗅𝖽(S)=&{li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆subscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼\mathsf{unfold}(S)=\&\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT and T𝑇Titalic_T starts with an output branching (i.e., 𝗎𝗇𝖿𝗈𝗅𝖽(T)={lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\oplus\{l_{j}:T_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT).

In the first two cases we have that the above initial transition is [S,ω]|[R,ωR][Si,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑆𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}\linebreak[S_% {i},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime% \prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ], for some iI𝑖𝐼i\in Iitalic_i ∈ italic_I. Given that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, it is possible to show that iJ𝑖𝐽i\in Jitalic_i ∈ italic_J, that TiSisubscript𝑇𝑖subscript𝑆𝑖T_{i}\operatorname{\leq}S_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT, and also [T,ω]|[R,ωR][Ti,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑇𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T_{i},\omega% ^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ]. Then we can apply the inductive hypothesis because TiSisubscript𝑇𝑖subscript𝑆𝑖T_{i}\operatorname{\leq}S_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT and [Si,ω′′′]|[R′′′,ωR′′′]conditionalsubscript𝑆𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S_{i},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime% \prime\prime}][ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] is a correct composition.

In the third case, given that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, and S𝑆Sitalic_S is controllable, we have that 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(S)=𝒜[{li:Ski}iJ]kK𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑆𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑖subscriptsubscript𝑆𝑘𝑖𝑖𝐽𝑘𝐾\mathsf{selUnfold}(S)=\mathcal{A}[{\oplus\{{l}_{i}:{S_{k}}_{i}\}_{i\in J}}]^{k% \in K}sansserif_selUnfold ( italic_S ) = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT, and 𝗎𝗇𝖿𝗈𝗅𝖽(T)={lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\oplus\{l_{j}:T_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT with Tj𝒜[Skj]kKsubscript𝑇𝑗𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾T_{j}\operatorname{\leq}\mathcal{A}[{S_{kj}}]^{k\in K}italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ≤ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT, for every jJ𝑗𝐽j\in Jitalic_j ∈ italic_J. We first observe that the sequence of transitions [S,ω]|[R,ωR][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[S^{% \prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ], with [S,ω′′]|[R′′,ωR′′]conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[S^{\prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}]\surd[ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √, includes at least one output selection ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT executed by one of the output selections filling the holes in 𝒜𝒜\mathcal{A}caligraphic_A. This label ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT is the first one emitted by the l.h.s. type after it has executed input branchings in 𝒜𝒜\mathcal{A}caligraphic_A. We have that the same sequence of transitions, excluding the output of ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT, can be executed from the configuration [𝒜[Skj]kK,ω]|[R,ωRlj]conditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ]. Such a sequence is [𝒜[Skj]kK,ω]|[R,ωRlj][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}]\stackrel{% {\scriptstyle}}{{\rightarrow}}^{*}[S^{\prime},\omega^{\prime\prime}]|[R^{% \prime\prime},\omega_{R}^{\prime\prime}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ], with [S,ω′′]|[R′′,ωR′′]conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[S^{\prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}]\surd[ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √; notice that it is shorter than the above one. We now consider [T,ω]|[R,ωR][Ti,ω]|[R,ωRlj]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑇𝑖𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T_{i},\omega% ]|[R,\omega_{R}\!\cdot\!{l_{j}}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ]. We can now apply the inductive hypothesis on the shorter sequence [𝒜[Skj]kK,ω]|[R,ωRlj][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}]\stackrel{% {\scriptstyle}}{{\rightarrow}}^{*}[S^{\prime},\omega^{\prime\prime}]|[R^{% \prime\prime},\omega_{R}^{\prime\prime}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ], because Tj𝒜[Skj]kKsubscript𝑇𝑗𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾T_{j}\operatorname{\leq}\mathcal{A}[{S_{kj}}]^{k\in K}italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ≤ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT (and because it is possible to prove that [𝒜[Skj]kK,ω]|[R,ωRlj]conditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ] is also a correct composition, see Proposition 22 in Appendix A.3). ∎

Theorem 9.

Given two session types T𝑇Titalic_T and S𝑆Sitalic_S, if TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S then TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S.

Sketch of the proof. If S𝑆Sitalic_S is not controllable, then the thesis trivially holds because TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S for every T𝑇Titalic_T.

Consider now S𝑆Sitalic_S controllable. The thesis is proved by showing that if TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S then, for every ω𝜔\omegaitalic_ω, R𝑅Ritalic_R, and ωRsubscript𝜔𝑅\omega_{R}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT such that [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition, we have that the following holds:

if [T,ω]|[R,ωR][T,ω]|[R,ωR]conditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[T,\omega]|[R,\omega_{R}]\rightarrow[T^{\prime},\omega^{\prime}]|[R^{\prime},% \omega_{R}^{\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] → [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] then there exists Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and [S,ω]|[R,ωR]conditionalsuperscript𝑆superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[S^{\prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] is a correct composition.

The above implies the thesis because, given TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S and the correct composition [S,ϵ]|[R,ϵ]conditional𝑆italic-ϵ𝑅italic-ϵ[S,\epsilon]|[R,\epsilon][ italic_S , italic_ϵ ] | [ italic_R , italic_ϵ ], if there exists a computation [T,ϵ]|[R,ϵ][T,ω]|[R,ωR]superscriptsuperscriptabsentconditional𝑇italic-ϵ𝑅italic-ϵconditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[T,\epsilon]|[R,\epsilon]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[T^{% \prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_T , italic_ϵ ] | [ italic_R , italic_ϵ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ], we can apply the above result on each step of the computation to prove that there exists Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and [S,ω]|[R,ωR]conditionalsuperscript𝑆superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[S^{\prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] is a correct composition. Then, by Proposition 8, we have that there exist T′′superscript𝑇′′T^{\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, ω′′superscript𝜔′′\omega^{\prime\prime}italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, R′′superscript𝑅′′R^{\prime\prime}italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, and ωR′′superscriptsubscript𝜔𝑅′′\omega_{R}^{\prime\prime}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that [T,ω]|[R,ωR][T′′,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅conditionalsuperscript𝑇′′superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[T^{\prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}]\stackrel{{% \scriptstyle}}{{\rightarrow}}^{*}[T^{\prime\prime},\omega^{\prime\prime}]|[R^{% \prime\prime},\omega_{R}^{\prime\prime}][ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] and [T′′,ω′′]|[R′′,ωR′′]conditionalsuperscript𝑇′′superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[T^{\prime\prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime% \prime}]\surd[ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √. ∎

{exa}

Let T={l1:&{l3:𝐞𝐧𝐝}}𝑇direct-sumconditional-setsubscript𝑙1conditional-setsubscript𝑙3𝐞𝐧𝐝T=\oplus\{l_{1}:\&\{l_{3}:\mathbf{end}\}\}italic_T = ⊕ { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : & { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : bold_end } } and S=&{l3:{l1:𝐞𝐧𝐝,l2:𝐞𝐧𝐝}}𝑆conditional-setsubscript𝑙3direct-sumconditional-setsubscript𝑙1:𝐞𝐧𝐝subscript𝑙2𝐞𝐧𝐝S=\&\{l_{3}:\!\oplus\{l_{1}:\mathbf{end},\ l_{2}:\mathbf{end}\}\}italic_S = & { italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : ⊕ { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : bold_end , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : bold_end } }. We have TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S, but T𝑇Titalic_T is not a fair asynchronous subtype of S𝑆Sitalic_S since {l1}{l1,l2}subscript𝑙1subscript𝑙1subscript𝑙2\{l_{1}\}\neq\{l_{1},l_{2}\}{ italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT } ≠ { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT }, i.e., covariance of outputs is not allowed.

3.1. Undecidability of fair asynchronous session subtyping

In this section we address the problem of checking fair asynchronous session subtyping, and we show that it is actually undecidable. We have already proved that the fair refinement relation square-image-of-or-equals\sqsubseteq is undecidable (Corollary 6) and that the fair asynchronous subtyping relation \operatorname{\leq} is a subset of the refinement relation square-image-of-or-equals\sqsubseteq (Theorem 9). From these results we cannot immediately conclude that fair asynchronous subtyping is also undecidable; hence we need a specific proof for this additional undecidability result. The approach we take has some commonalities with the one adopted in Section 2.3, as we also proceed by reduction from undecidability properties in queue machines. Nevertheless, there are several relevant differences. First, we consider termination in queue machines instead of state reachability. Then we need to slightly modify the encodings of both the finite control and of the queue of the considered machine. And finally, the proof of correctness of the encoding is significantly different as subtyping is defined on the syntax of types, while refinement is defined on the operational semantics of (the parallel composition of) session types.

As anticipated above, we reduce the problem of checking the (non)termination of a queue machine to the problem of checking subtyping between two session types. In Definition 2.3 we have defined (q,γ)M(q,γ)subscript𝑀𝑞𝛾superscript𝑞superscript𝛾(q,\gamma)\rightarrow_{M}(q^{\prime},\gamma^{\prime})( italic_q , italic_γ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) denoting computation steps of a queue machine. We have that one queue machine M𝑀Mitalic_M terminates if and only if there exists a configuration with empty queue that is reachable from the initial configuration, i.e., (s,$)M(q,ϵ)superscriptsubscript𝑀𝑠currency-dollarsuperscript𝑞italic-ϵ(s,\$)\rightarrow_{M}^{*}(q^{\prime},\epsilon)( italic_s , $ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ϵ ). This holds because the transition function is total in queue machines, hence if the queue is not empty there is always a possible transition. In case the queue machine does not terminate, we have that (q,$)M(q,γ)superscriptsubscript𝑀𝑞currency-dollarsuperscript𝑞superscript𝛾(q,\$)\rightarrow_{M}^{*}(q^{\prime},\gamma^{\prime})( italic_q , $ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) implies the existence of an additional computation step (q,γ)M(q′′,γ′′)subscript𝑀superscript𝑞superscript𝛾superscript𝑞′′superscript𝛾′′(q^{\prime},\gamma^{\prime})\rightarrow_{M}(q^{\prime\prime},\gamma^{\prime% \prime})( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT ( italic_q start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ).

Given a queue machine M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) and an additional ending symbol EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ, we now define the types T=[[[M,_,E]]]𝑇delimited-[]delimited-[]𝑀_𝐸T=[\![\![{M,\_,E}]\!]\!]italic_T = [ [ [ italic_M , _ , italic_E ] ] ] and S=[[[M,E]]]𝑆delimited-[]delimited-[]𝑀𝐸S=[\![\![{M,E}]\!]\!]italic_S = [ [ [ italic_M , italic_E ] ] ] in such a way that M𝑀Mitalic_M does not terminate if and only if TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. The encodings [[[M,_,E]]]delimited-[]delimited-[]𝑀_𝐸[\![\![{M,\_,E}]\!]\!][ [ [ italic_M , _ , italic_E ] ] ] and [[[M,E]]]delimited-[]delimited-[]𝑀𝐸[\![\![{M,E}]\!]\!][ [ [ italic_M , italic_E ] ] ] are similar to the corresponding encodings [[M,qf,E]]delimited-[]𝑀subscript𝑞𝑓𝐸[\![M,q_{f},E]\!][ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] and [[M,E]]delimited-[]𝑀𝐸[\![M,E]\!][ [ italic_M , italic_E ] ] defined in Definitions 2.3 and 2.3, but with the following differences:

  • there is no specific target state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT;

  • the encoding [[[M,E]]]delimited-[]delimited-[]𝑀𝐸[\![\![{M,E}]\!]\!][ [ [ italic_M , italic_E ] ] ] starts with an input branching with only one branch labeled with the initial queue symbol $currency-dollar\$$ and continuation corresponding to the producer/consumer [[M,E]]delimited-[]𝑀𝐸[\![M,E]\!][ [ italic_M , italic_E ] ] as defined in Definition 2.3;

  • in order to be a potential subtype of S=[[[M,E]]]𝑆delimited-[]delimited-[]𝑀𝐸S=[\![\![{M,E}]\!]\!]italic_S = [ [ [ italic_M , italic_E ] ] ], all of the output selections in T=[[[M,_,E]]]𝑇delimited-[]delimited-[]𝑀_𝐸T=[\![\![{M,\_,E}]\!]\!]italic_T = [ [ [ italic_M , _ , italic_E ] ] ] must have branchings for all of the symbols in Γ{E}Γ𝐸\Gamma\cup\{E\}roman_Γ ∪ { italic_E } (because these are the labels in the output selection in the potential supertype); among all of these branchings only one will be consistent with the encoding of the finite control, while the continuations in the other branchings are guaranteed to be always good subtypes (this is guaranteed by a type that nondeterministically produces symbols, and that after producing the ending symbol E𝐸Eitalic_E it is able to recursively consume all possible symbols in ΓΓ\Gammaroman_Γ, and then become 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end after consuming the ending symbol E𝐸Eitalic_E).

{defi}

[New Finite Control Encoding] Let M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) be a queue machine and let EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ be the additional ending symbol. We define [[[M,_,E]]]delimited-[]delimited-[]𝑀_𝐸[\![\![{M,\_,E}]\!]\!][ [ [ italic_M , _ , italic_E ] ] ] as follows:

[[[M,_,E]]]=[[[s]]]delimited-[]delimited-[]𝑀_𝐸superscriptdelimited-[]delimited-[]delimited-[]𝑠[\![\![{M,\_,E}]\!]\!]\ =[\![\![{s}]\!]\!]^{\emptyset}[ [ [ italic_M , _ , italic_E ] ] ] = [ [ [ italic_s ] ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT

with, given qQ𝑞𝑄q\in Qitalic_q ∈ italic_Q and 𝒮Q𝒮𝑄\mathcal{S}\subseteq Qcaligraphic_S ⊆ italic_Q, [[[q]]]𝒮superscriptdelimited-[]delimited-[]delimited-[]𝑞𝒮[\![\![{q}]\!]\!]^{\mathcal{S}}[ [ [ italic_q ] ] ] start_POSTSUPERSCRIPT caligraphic_S end_POSTSUPERSCRIPT is defined as follows:

[[[q]]]𝒮={μ𝐪.&{A:{{B1ABnAA}}q𝒮{q}}AΓif q𝒮 and δ(q,A)=(q,B1ABnAA)𝐪if q𝒮superscriptdelimited-[]delimited-[]delimited-[]𝑞𝒮casesformulae-sequence𝜇𝐪subscriptconditional-set𝐴superscriptsubscriptsubscriptsuperscript𝐵𝐴1subscriptsuperscript𝐵𝐴subscript𝑛𝐴superscript𝑞𝒮𝑞𝐴Γif 𝑞𝒮 and 𝛿𝑞𝐴superscript𝑞subscriptsuperscript𝐵𝐴1subscriptsuperscript𝐵𝐴subscript𝑛𝐴missing-subexpression𝐪if q𝒮\begin{array}[]{l}[\![\![{q}]\!]\!]^{\mathcal{S}}=\left\{\begin{array}[]{l}\mu% \mathbf{q}.\&\{{A}\!:\!{{\{\!\!\{{B^{A}_{1}\cdots B^{A}_{n_{A}}}\}\!\!\}}_{q^{% \prime}}^{\mathcal{S}\cup\{q\}}}\}_{A\in\Gamma}\\[2.84526pt] \hskip 25.6073pt\text{if }q\not\in{\mathcal{S}}\text{ and }\delta(q,A)=(q^{% \prime},B^{A}_{1}\cdots B^{A}_{n_{A}})\\ \\ \mathbf{q}\qquad\mbox{if $q\in{\mathcal{S}}$}\end{array}\right.\end{array}start_ARRAY start_ROW start_CELL [ [ [ italic_q ] ] ] start_POSTSUPERSCRIPT caligraphic_S end_POSTSUPERSCRIPT = { start_ARRAY start_ROW start_CELL italic_μ bold_q . & { italic_A : { { italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_S ∪ { italic_q } end_POSTSUPERSCRIPT } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT end_CELL end_ROW start_ROW start_CELL if italic_q ∉ caligraphic_S and italic_δ ( italic_q , italic_A ) = ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT end_POSTSUBSCRIPT ) end_CELL end_ROW start_ROW start_CELL end_CELL end_ROW start_ROW start_CELL bold_q if italic_q ∈ caligraphic_S end_CELL end_ROW end_ARRAY end_CELL end_ROW end_ARRAY

where

{{B1Bm}}r𝒯={[[[r]]]𝒯if m=0({B1:{{B2Bm}}r𝒯}{A:V}AΓ{B1}{E:V})otherwise\begin{array}[]{l}{\{\!\!\{{B_{1}\cdots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}\!=\!% \left\{\!\!\begin{array}[]{ll}\!{[\![\![{r}]\!]\!]}^{\mathcal{T}}&\text{if }m=% 0\\ \begin{array}[]{ll}\!\!\!\!\oplus&\!\!\!\!\big{(}\big{\{}B_{1}:{\{\!\!\{{B_{2}% \ldots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}\big{\}}\cup\\ &\!\big{\{}{A:V}\big{\}}_{A\in\Gamma\setminus\{B_{1}\}}\cup\{E:V^{\prime}\}% \big{)}\end{array}&\text{otherwise}\end{array}\right.\end{array}start_ARRAY start_ROW start_CELL { { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT = { start_ARRAY start_ROW start_CELL [ [ [ italic_r ] ] ] start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT end_CELL start_CELL if italic_m = 0 end_CELL end_ROW start_ROW start_CELL start_ARRAY start_ROW start_CELL ⊕ end_CELL start_CELL ( { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : { { italic_B start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT … italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT } ∪ end_CELL end_ROW start_ROW start_CELL end_CELL start_CELL { italic_A : italic_V } start_POSTSUBSCRIPT italic_A ∈ roman_Γ ∖ { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT } end_POSTSUBSCRIPT ∪ { italic_E : italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } ) end_CELL end_ROW end_ARRAY end_CELL start_CELL otherwise end_CELL end_ROW end_ARRAY end_CELL end_ROW end_ARRAY

with V=μ𝐭.({A:𝐭}AΓ{E:V})formulae-sequence𝑉𝜇𝐭direct-sumsubscriptconditional-set𝐴𝐭𝐴Γconditional-set𝐸superscript𝑉V=\mu\mathbf{\mathbf{t}}.\big{(}\oplus\{{A}:{\mathbf{t}}\}_{A\in\Gamma}\cup\{E% :V^{\prime}\}\big{)}italic_V = italic_μ bold_t . ( ⊕ { italic_A : bold_t } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } ) and V=μ𝐭.(&{A:𝐭}AΓ{E:𝐞𝐧𝐝})formulae-sequencesuperscript𝑉𝜇𝐭subscriptconditional-set𝐴𝐭𝐴Γconditional-set𝐸𝐞𝐧𝐝V^{\prime}=\mu\mathbf{\mathbf{t}}.\big{(}\&\{{A}\!:\!{\mathbf{t}}\}_{A\in% \Gamma}\cup\{E:\mathbf{end}\}\big{)}italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = italic_μ bold_t . ( & { italic_A : bold_t } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : bold_end } ).

{defi}

[New Producer/consumer] Let M=(Q,Γ,$,s,δ)𝑀𝑄Γcurrency-dollar𝑠𝛿M=(Q,\Gamma,\$,s,\delta)italic_M = ( italic_Q , roman_Γ , $ , italic_s , italic_δ ) be a queue machine and EΓ𝐸ΓE\not\in\Gammaitalic_E ∉ roman_Γ be the ending symbol. We define [[[M,E]]]delimited-[]delimited-[]𝑀𝐸[\![\![{M,E}]\!]\!][ [ [ italic_M , italic_E ] ] ] as

[[[M,E]]]=&{$:[[M,E]]}delimited-[]delimited-[]𝑀𝐸conditional-setcurrency-dollardelimited-[]𝑀𝐸[\![\![{M,E}]\!]\!]=\&\{\$:[\![M,E]\!]\}[ [ [ italic_M , italic_E ] ] ] = & { $ : [ [ italic_M , italic_E ] ] }

with [[M,E]]delimited-[]𝑀𝐸[\![M,E]\!][ [ italic_M , italic_E ] ] as defined in Definition 2.3.

We now prove that the above two types T=[[[M,_,E]]]𝑇delimited-[]delimited-[]𝑀_𝐸T=[\![\![{M,\_,E}]\!]\!]italic_T = [ [ [ italic_M , _ , italic_E ] ] ] and S=[[[M,E]]]𝑆delimited-[]delimited-[]𝑀𝐸S=[\![\![{M,E}]\!]\!]italic_S = [ [ [ italic_M , italic_E ] ] ] are such that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S if and only if the machine M𝑀Mitalic_M does not terminate. We report a sketch of the proof, the details are in Appendix A.4.

Theorem 10.

Given a queue machine M𝑀Mitalic_M and the ending symbol E𝐸Eitalic_E, consider T=[[[M,_,E]]]𝑇delimited-[]delimited-[]𝑀_𝐸T=[\![\![{M,\_,E}]\!]\!]italic_T = [ [ [ italic_M , _ , italic_E ] ] ] and S=[[[M,E]]]𝑆delimited-[]delimited-[]𝑀𝐸S=[\![\![{M,E}]\!]\!]italic_S = [ [ [ italic_M , italic_E ] ] ]. We have that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S if and only if M𝑀Mitalic_M does not terminate.

Sketch of the proof. The only-if part is proved by considering the contrapositive statement, that is, if the queue machine M𝑀Mitalic_M terminates then TS𝑇𝑆T\not\!\!\!\,\operatorname{\leq}Sitalic_T not ≤ italic_S. If the queue machine terminates, we have that (s,$)M(q,ϵ)superscriptsubscript𝑀𝑠currency-dollarsuperscript𝑞italic-ϵ(s,\$)\rightarrow_{M}^{*}(q^{\prime},\epsilon)( italic_s , $ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ϵ ). Consider now the pair of types (T,S)𝑇𝑆(T,S)( italic_T , italic_S ) with T=[[[M,_,E]]]𝑇delimited-[]delimited-[]𝑀_𝐸T=[\![\![{M,\_,E}]\!]\!]italic_T = [ [ [ italic_M , _ , italic_E ] ] ] and S=[[[M,E]]]𝑆delimited-[]delimited-[]𝑀𝐸S=[\![\![{M,E}]\!]\!]italic_S = [ [ [ italic_M , italic_E ] ] ]. If, by contradiction, TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, since S𝑆Sitalic_S is controllable (it is compliant, e.g., with its dual) we have that by Definition 3 there exists a fair asynchronous subtyping relation \mathcal{R}caligraphic_R such that (T,S)𝑇𝑆(T,S)\in\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R. By applying the definition of fair asynchronous subtyping relation we have that \mathcal{R}caligraphic_R will have to include other pairs of types (T′′,S′′)superscript𝑇′′superscript𝑆′′(T^{\prime\prime},S^{\prime\prime})( italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) corresponding with configurations (q′′,γ′′)superscript𝑞′′superscript𝛾′′(q^{\prime\prime},\gamma^{\prime\prime})( italic_q start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) reachable in the queue machine M𝑀Mitalic_M. The types T′′superscript𝑇′′T^{\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT represent the corresponding state q′′superscript𝑞′′q^{\prime\prime}italic_q start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, while the types S′′superscript𝑆′′S^{\prime\prime}italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT represent the corresponding queue γ′′superscript𝛾′′\gamma^{\prime\prime}italic_γ start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT. Consider now the pair of types (Tf,Sf)subscript𝑇𝑓subscript𝑆𝑓(T_{f},S_{f})( italic_T start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_S start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ) corresponding with the final configuration (q,ϵ)superscript𝑞italic-ϵ(q^{\prime},\epsilon)( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ϵ ): Tfsubscript𝑇𝑓T_{f}italic_T start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT starts with an input branching (representing the willingness to consume one symbol from the queue) while Sfsubscript𝑆𝑓S_{f}italic_S start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT starts with an output selection (in fact, the representation of the queue starts with a sequence of input branchings, one for each symbol in the queue, followed by an output selection and, given that it represents the empty queue, the initial sequence of input branching is absent). Summarising, we have that (Tf,Sf)subscript𝑇𝑓subscript𝑆𝑓(T_{f},S_{f})\in\mathcal{R}( italic_T start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_S start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ) ∈ caligraphic_R, Tfsubscript𝑇𝑓T_{f}italic_T start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT starts with an input branching, and Sfsubscript𝑆𝑓S_{f}italic_S start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT with an output selection: hence there is a pair in \mathcal{R}caligraphic_R which does not satisfy the item for input selection in Definition 3, thus contradicting the initial assumption about \mathcal{R}caligraphic_R being a fair asynchronous subtyping relation.

The if part is proved by showing that if the queue machine M𝑀Mitalic_M does not terminate then there exists a fair asynchronous subtyping relation \mathcal{R}caligraphic_R that contains the pair (T,S)𝑇𝑆(T,S)( italic_T , italic_S ), hence TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. There are two kinds of pairs in \mathcal{R}caligraphic_R: (i) the pairs discussed in the above only-if part of the proof that corresponds to the path in the subtyping simulation game that reproduces the computation of the queue machine M𝑀Mitalic_M, and (ii) other pairs corresponding to alternative paths. Here, we only comment the new pairs of kind (ii). The l.h.s. types in these pairs are generated by considering the alternative branches in the types {{B1Bm}}r𝒯superscriptsubscriptsubscript𝐵1subscript𝐵𝑚𝑟𝒯{\{\!\!\{{B_{1}\cdots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}{ { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT in Definition 3.1, namely those involving the types denoted with V𝑉Vitalic_V and Vsuperscript𝑉V^{\prime}italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. These types are of two kinds: (a) they are able to recursively perform all possible outputs until the label E𝐸Eitalic_E is selected (type V𝑉Vitalic_V), or (b) they are able to recursively perform all possible inputs until the label E𝐸Eitalic_E is selected (type Vsuperscript𝑉V^{\prime}italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT). All of these pairs satisfy the constraints in Definition 3 (under the assumption that also a final pair (𝐞𝐧𝐝,𝐞𝐧𝐝)𝐞𝐧𝐝𝐞𝐧𝐝(\mathbf{end},\mathbf{end})( bold_end , bold_end ) belongs to \mathcal{R}caligraphic_R). Summarising, there exists a fair asynchronous subtyping relation \mathcal{R}caligraphic_R such that (T,S)𝑇𝑆(T,S)\in\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R in that this is the first pair of the kind (i) above. Hence we can conclude that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. ∎

As a direct consequence of the above theorem and the undecidability of termination in queue machines, we can conclude that fair asynchronous subtyping (Definition 3) is also undecidable.

Corollary 11.

Given two session types T𝑇Titalic_T and S𝑆Sitalic_S, it is in general undecidable to check whether TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S.

4. A Sound Algorithm for Fair Asynchronous Subtyping

We propose an algorithm which soundly verifies whether a session type is a fair asynchronous subtype of another. The algorithm relies on building a tree whose nodes are labelled by configurations of the simulation game induced by Definition 3. The algorithm analyses the tree to identify witness subtrees which contain input contexts that are growing following a recognisable pattern.

{exa}

Recall the satellite communication example (Figure 1). The spacecraft with protocol TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT may be a replacement for an older generation of spacecraft which follows the more complicated protocol TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT, see Figure 3. Type TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT notably allows the reception of telecommands to be interleaved with the emission of telemetries. The new spacecraft may safely replace the old one because TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\operatorname{\leq}T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT.

However, checking TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\operatorname{\leq}T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT leads to an infinite accumulation of input contexts, hence it requires to consider infinitely many pairs of session types. E.g., after TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT selects the output label 𝑡𝑚𝑡𝑚\mathit{tm}italic_tm twice, the subtyping simulation game considers the pair (TS,TS′′)subscript𝑇𝑆subscriptsuperscript𝑇′′𝑆(T_{S},T^{\prime\prime}_{S})( italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT , italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ), where TS′′subscriptsuperscript𝑇′′𝑆T^{\prime\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT is given in Figure 3. The pairs generated for this example illustrate a common recognisable pattern where some branches grow infinitely (the 𝑡𝑐𝑡𝑐\mathit{tc}italic_tc-branch), while others stay stable throughout the derivation (the 𝑑𝑜𝑛𝑒𝑑𝑜𝑛𝑒\mathit{done}italic_done-branch). The crux of our algorithm is to use a finite parametric characterisation of the infinitely many pairs occurring in the check of TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\operatorname{\leq}T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT.

The simulation tree for TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, written 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ), is the labelled tree representing the simulation game for TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, i.e., 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) is a tuple (N,n0,,λ)𝑁subscript𝑛0𝜆(N,n_{0},\twoheadrightarrow,\lambda)( italic_N , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT , ↠ , italic_λ ) where N𝑁Nitalic_N is its set of nodes, n0Nsubscript𝑛0𝑁n_{0}\in Nitalic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT ∈ italic_N is its root, \twoheadrightarrow is its transition relation, and λ𝜆\lambdaitalic_λ is its labelling function, such that λ(n0)=(S,T)𝜆subscript𝑛0𝑆𝑇\lambda(n_{0})=(S,T)italic_λ ( italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT ) = ( italic_S , italic_T ). We omit the formal definition of \twoheadrightarrow, as it is straightforward from Definition 3 following the subtyping simulation game discussed after that definition. We give an example below.

Notice that the simulation tree 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) is defined only when S𝑆Sitalic_S is controllable, since TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S holds without needing to play the subtyping simulation game if S𝑆Sitalic_S is not controllable. We say that a branch of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) is successful if it is infinite or if it finishes in a leaf labelled by (𝐞𝐧𝐝,𝐞𝐧𝐝)𝐞𝐧𝐝𝐞𝐧𝐝(\mathbf{end},\mathbf{end})( bold_end , bold_end ). All other branches are unsuccessful. Under the assumption that S𝑆Sitalic_S is controllable, we have that all branches of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) are successful if and only if TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. As a consequence checking whether all branches of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) are successful is generally undecidable. It is possible to identify a branch as successful if it visits finitely many pairs (or node labels), see Example 3; but in general a branch may generate infinitely many pairs, see Examples 4 and 4.

0011112222333344445555?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over
TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT = μ𝐭𝜇𝐭\mu\mathbf{t}italic_μ bold_t .&{.\&\big{\{}. & { 𝑡𝑐::𝑡𝑐absent\mathit{tc}:italic_tc : {𝑡𝑚:𝐭,𝑜𝑣𝑒𝑟:μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}},\oplus\{\mathit{tm}:\mathbf{t},\mathit{over}:\mu\mathbf{t^{\prime}}.~{}\&\{% \mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:\mathbf{end}\}\},⊕ { italic_tm : bold_t , italic_over : italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } } ,
𝑑𝑜𝑛𝑒::𝑑𝑜𝑛𝑒absent\mathit{done}:italic_done : μ𝐭′′.{𝑡𝑚:𝐭′′,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝}}\mu\mathbf{t^{\prime\prime}}.\oplus\{\mathit{tm}:\mathbf{t^{\prime\prime}},% \mathit{over}:\mathbf{end}\}\big{\}}italic_μ bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT . ⊕ { italic_tm : bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_over : bold_end } }
TS′′subscriptsuperscript𝑇′′𝑆T^{\prime\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT = &{\phantom{.}\&\big{\{}& { 𝑡𝑐::𝑡𝑐absent\mathit{tc}:italic_tc : &{\&\{& { 𝑡𝑐::𝑡𝑐absent\mathit{tc}:italic_tc : TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT,
𝑑𝑜𝑛𝑒::𝑑𝑜𝑛𝑒absent\mathit{done}:italic_done : μ𝐭′′.{𝑡𝑚:𝐭′′,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝}formulae-sequence𝜇superscript𝐭′′direct-sumconditional-set𝑡𝑚:superscript𝐭′′𝑜𝑣𝑒𝑟𝐞𝐧𝐝\mu\mathbf{t^{\prime\prime}}.\oplus\{\mathit{tm}:\mathbf{t^{\prime\prime}},% \mathit{over}:\mathbf{end}\}italic_μ bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT . ⊕ { italic_tm : bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_over : bold_end } }}\}},
𝑑𝑜𝑛𝑒::𝑑𝑜𝑛𝑒absent\mathit{done}:italic_done : μ𝐭′′.{𝑡𝑚:𝐭′′,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝}formulae-sequence𝜇superscript𝐭′′direct-sumconditional-set𝑡𝑚:superscript𝐭′′𝑜𝑣𝑒𝑟𝐞𝐧𝐝\mu\mathbf{t^{\prime\prime}}.\oplus\{\mathit{tm}:\mathbf{t^{\prime\prime}},% \mathit{over}:\mathbf{end}\}italic_μ bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT . ⊕ { italic_tm : bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_over : bold_end } }}\big{\}}}
Figure 3. TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT is an alternative session type for TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT, see Example 4.

In order to support types that generate unbounded accumulation, we characterise finite subtrees — called witness subtrees, see Definition 4 — such that all the branches that traverse these finite subtrees are guaranteed to be successful.

Notation

We give a few auxiliary definitions and notations. Hereafter 𝒜𝒜\mathcal{A}caligraphic_A and 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT range over extended input contexts, i.e., input contexts that may contain distinct holes with the same index. These are needed to deal with unfoldings of input contexts, see Example 4.

The set of reductions of an input context 𝒜𝒜\mathcal{A}caligraphic_A is the minimal set 𝒮𝒮\mathcal{S}caligraphic_S s.t. {enumerate*}[label=()]

𝒜𝒮𝒜𝒮\mathcal{A}\in\mathcal{S}caligraphic_A ∈ caligraphic_S;

if &{li:𝒜i}iI𝒮subscriptconditional-setsubscript𝑙𝑖subscript𝒜𝑖𝑖𝐼𝒮\&\{l_{i}:\mathcal{A}_{i}\}_{i\in I}\in\mathcal{S}& { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : caligraphic_A start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT ∈ caligraphic_S then iI.𝒜i𝒮formulae-sequencefor-all𝑖𝐼subscript𝒜𝑖𝒮\forall i\in I.\mathcal{A}_{i}\in\mathcal{S}∀ italic_i ∈ italic_I . caligraphic_A start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∈ caligraphic_S and

if μ𝐭.𝒜𝒮formulae-sequence𝜇𝐭superscript𝒜𝒮\mu\mathbf{t}.\mathcal{A}^{\prime}\in\mathcal{S}italic_μ bold_t . caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ caligraphic_S then 𝒜{μ𝐭.𝒜/𝐭}𝒮superscript𝒜formulae-sequence𝜇𝐭superscript𝒜𝐭𝒮\mathcal{A}^{\prime}\{\nicefrac{{\mu\mathbf{t}.\mathcal{A}^{\prime}}}{{\mathbf% {t}}}\}\in\mathcal{S}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT { / start_ARG italic_μ bold_t . caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_ARG start_ARG bold_t end_ARG } ∈ caligraphic_S. Notice that due to unfolding (item 4), the reductions of an input context may contain extended input contexts. Moreover, given a reduction 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT of 𝒜𝒜\mathcal{A}caligraphic_A, we have that ℎ𝑜𝑙𝑒𝑠(𝒜)ℎ𝑜𝑙𝑒𝑠(𝒜)ℎ𝑜𝑙𝑒𝑠superscript𝒜ℎ𝑜𝑙𝑒𝑠𝒜\mathit{holes}(\mathcal{A}^{\prime})\subseteq\mathit{holes}(\mathcal{A})italic_holes ( caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ⊆ italic_holes ( caligraphic_A ).

{exa}

Consider the following extended input contexts: {mathpar} A_1 = μt . &{ l_1 : [ ]^1,  l_2 : &{ l_3 : t } }

A_2 = &{ l_3 : μt . &{ l_1 : [ ]^1,  l_2 : &{ l_3 : t } } }

unfold(A_1) = &{ l_1 : [ ]^1,  l_2 : &{ l_3 : μt . &{ l_1 : [ ]^1,  l_2 : &{ l_3 : t } } } } Context 𝒜2subscript𝒜2\mathcal{A}_{2}caligraphic_A start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is a reduction of 𝒜1subscript𝒜1\mathcal{A}_{1}caligraphic_A start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT, i.e., one can reach 𝒜2subscript𝒜2\mathcal{A}_{2}caligraphic_A start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT from 𝒜1subscript𝒜1\mathcal{A}_{1}caligraphic_A start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT, by unfolding 𝒜1subscript𝒜1\mathcal{A}_{1}caligraphic_A start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and executing the input l2subscript𝑙2l_{2}italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT. Context 𝗎𝗇𝖿𝗈𝗅𝖽(𝒜1)𝗎𝗇𝖿𝗈𝗅𝖽subscript𝒜1\mathsf{unfold}(\mathcal{A}_{1})sansserif_unfold ( caligraphic_A start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ) is also a reduction of 𝒜1subscript𝒜1\mathcal{A}_{1}caligraphic_A start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT. Observe that 𝗎𝗇𝖿𝗈𝗅𝖽(𝒜1)𝗎𝗇𝖿𝗈𝗅𝖽subscript𝒜1\mathsf{unfold}(\mathcal{A}_{1})sansserif_unfold ( caligraphic_A start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ) contains two distinct holes indexed by 1111.

Given an extended context 𝒜𝒜\mathcal{A}caligraphic_A and a set of hole indices K𝐾Kitalic_K such that Kℎ𝑜𝑙𝑒𝑠(𝒜)𝐾ℎ𝑜𝑙𝑒𝑠𝒜K\subseteq\mathit{holes}(\mathcal{A})italic_K ⊆ italic_holes ( caligraphic_A ), we use the following shorthands. Given a type Tksubscript𝑇𝑘T_{k}italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT for each kK𝑘𝐾k\in Kitalic_k ∈ italic_K, we write 𝒜TkkK𝒜superscriptsubscript𝑇𝑘𝑘𝐾\mathcal{A}\lfloor T_{k}\rfloor^{k\in K}caligraphic_A ⌊ italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT for the extended context obtained by replacing each hole kK𝑘𝐾k\in Kitalic_k ∈ italic_K in 𝒜𝒜\mathcal{A}caligraphic_A by Tksubscript𝑇𝑘T_{k}italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT. Also, given an extended context 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT we write 𝒜𝒜K𝒜superscriptdelimited-⟨⟩superscript𝒜𝐾\mathcal{A}\langle\mathcal{A}^{\prime}\rangle^{K}caligraphic_A ⟨ caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_K end_POSTSUPERSCRIPT for the extended context obtained by replacing each hole kK𝑘𝐾k\in Kitalic_k ∈ italic_K in 𝒜𝒜\mathcal{A}caligraphic_A by 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. When K={k}𝐾𝑘K=\{k\}italic_K = { italic_k }, we often omit K𝐾Kitalic_K and write, e.g., 𝒜𝒜k𝒜superscriptdelimited-⟨⟩superscript𝒜𝑘\mathcal{A}\langle\mathcal{A}^{\prime}\rangle^{k}caligraphic_A ⟨ caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_k end_POSTSUPERSCRIPT and 𝒜Tkk𝒜superscriptsubscript𝑇𝑘𝑘\mathcal{A}\lfloor T_{k}\rfloor^{k}caligraphic_A ⌊ italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k end_POSTSUPERSCRIPT.

(TS,𝒜TS,T1{1,2})subscript𝑇𝑆𝒜superscriptsubscriptsuperscript𝑇𝑆subscriptsuperscript𝑇112(T_{S},\;\mathcal{A}\lfloor T^{\prime}_{S},T^{\prime}_{1}\rfloor^{\{1,2\}})( italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT , caligraphic_A ⌊ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT , italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT { 1 , 2 } end_POSTSUPERSCRIPT )(μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝},𝒜𝒜T1′′11𝐞𝐧𝐝2)formulae-sequence𝜇superscript𝐭conditional-set𝑡𝑐:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝𝒜superscriptdelimited-⟨⟩𝒜superscriptsubscriptsuperscript𝑇′′111superscript𝐞𝐧𝐝2(\mu\mathbf{t^{\prime}}.\&\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:% \mathbf{end}\},\;\mathcal{A}\langle\mathcal{A}\lfloor T^{\prime\prime}_{1}% \rfloor^{1}\rangle^{1}\lfloor\mathbf{end}\rfloor^{2})( italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } , caligraphic_A ⟨ caligraphic_A ⌊ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⌊ bold_end ⌋ start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT )(μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝},𝒜T1′′1𝐞𝐧𝐝2)formulae-sequence𝜇superscript𝐭conditional-set𝑡𝑐:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝𝒜superscriptsubscriptsuperscript𝑇′′11superscript𝐞𝐧𝐝2(\mu\mathbf{t^{\prime}}.\&\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:% \mathbf{end}\},\;\mathcal{A}\lfloor T^{\prime\prime}_{1}\rfloor^{1}\lfloor% \mathbf{end}\rfloor^{2})( italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } , caligraphic_A ⌊ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⌊ bold_end ⌋ start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT )(𝐞𝐧𝐝,𝐞𝐧𝐝)𝐞𝐧𝐝𝐞𝐧𝐝(\mathbf{end},\;\mathbf{end})( bold_end , bold_end )(TS,𝒜𝒜TS11T12)subscript𝑇𝑆𝒜superscriptdelimited-⟨⟩𝒜superscriptsubscriptsuperscript𝑇𝑆11superscriptsubscriptsuperscript𝑇12(T_{S},\;\mathcal{A}\langle\mathcal{A}\lfloor T^{\prime}_{S}\rfloor^{1}\rangle% ^{1}\lfloor T^{\prime}_{1}\rfloor^{2})( italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT , caligraphic_A ⟨ caligraphic_A ⌊ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⌊ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT )!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm(TS,TS)subscript𝑇𝑆subscriptsuperscript𝑇𝑆(T_{S},\;T^{\prime}_{S})( italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT , italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT )!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm(μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝},𝒜T1′′1𝐞𝐧𝐝2)formulae-sequence𝜇superscript𝐭conditional-set𝑡𝑐:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝𝒜superscriptsubscriptsuperscript𝑇′′11superscript𝐞𝐧𝐝2(\mu\mathbf{t^{\prime}}.\&\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:% \mathbf{end}\},\;\mathcal{A}\lfloor T^{\prime\prime}_{1}\rfloor^{1}\lfloor% \mathbf{end}\rfloor^{2})( italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } , caligraphic_A ⌊ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⌊ bold_end ⌋ start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT )(𝐞𝐧𝐝,𝐞𝐧𝐝)𝐞𝐧𝐝𝐞𝐧𝐝(\mathbf{end},\;\mathbf{end})( bold_end , bold_end )(μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝},T1′′)formulae-sequence𝜇superscript𝐭conditional-set𝑡𝑐:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝subscriptsuperscript𝑇′′1(\mu\mathbf{t^{\prime}}.\&\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:% \mathbf{end}\},\;T^{\prime\prime}_{1})( italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } , italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT )(𝐞𝐧𝐝,𝐞𝐧𝐝)𝐞𝐧𝐝𝐞𝐧𝐝(\mathbf{end},\;\mathbf{end})( bold_end , bold_end )(μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝},T1′′)formulae-sequence𝜇superscript𝐭conditional-set𝑡𝑐:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝subscriptsuperscript𝑇′′1(\mu\mathbf{t^{\prime}}.\&\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:% \mathbf{end}\},\;T^{\prime\prime}_{1})( italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } , italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT )!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc=
𝒜𝒜\mathcal{A}caligraphic_A ==\;= &{𝑡𝑐:[]1,𝑑𝑜𝑛𝑒:[]2}conditional-set𝑡𝑐:superscript1𝑑𝑜𝑛𝑒superscript2\&\{\mathit{tc}:[\,]^{1},\mathit{done}:[\,]^{2}\}& { italic_tc : [ ] start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , italic_done : [ ] start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT }
T1subscriptsuperscript𝑇1T^{\prime}_{1}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ==\;= μ𝐭′′.{𝑡𝑚:𝐭′′,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝}formulae-sequence𝜇superscript𝐭′′direct-sumconditional-set𝑡𝑚:superscript𝐭′′𝑜𝑣𝑒𝑟𝐞𝐧𝐝\mu\mathbf{t^{\prime\prime}}.\oplus\{\mathit{tm}:\mathbf{t^{\prime\prime}},% \mathit{over}:\mathbf{end}\}italic_μ bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT . ⊕ { italic_tm : bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_over : bold_end }
T1′′subscriptsuperscript𝑇′′1T^{\prime\prime}_{1}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ==\;= μ𝐭.&{𝑡𝑐:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}formulae-sequence𝜇superscript𝐭conditional-set𝑡𝑐:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝\mu\mathbf{t^{\prime}}.~{}\&\{\mathit{tc}:\mathbf{t^{\prime}},\mathit{done}:% \mathbf{end}\}italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end }
Figure 4. Simulation tree for TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\leq T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT (Figures 1 and 3), the root of the tree is in bold.
{exa}

Using the above notation and posing 𝒜=&{𝑡𝑐:[]1,𝑑𝑜𝑛𝑒:[]2}𝒜conditional-set𝑡𝑐:superscript1𝑑𝑜𝑛𝑒superscript2\mathcal{A}=\&\{\mathit{tc}:[\,]^{1},\mathit{done}:[\,]^{2}\}caligraphic_A = & { italic_tc : [ ] start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , italic_done : [ ] start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT }, we can rewrite TS′′subscriptsuperscript𝑇′′𝑆T^{\prime\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT (Figure 3) as 𝒜𝒜TS11μ𝐭′′.{𝑡𝑚:𝐭′′,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝}2\mathcal{A}\langle\mathcal{A}\lfloor T^{\prime}_{S}\rfloor^{1}\rangle^{1}% \lfloor\mu\mathbf{t^{\prime\prime}}.\oplus\{\mathit{tm}:\mathbf{t^{\prime% \prime}},\mathit{over}:\mathbf{end}\}\rfloor^{2}caligraphic_A ⟨ caligraphic_A ⌊ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⌊ italic_μ bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT . ⊕ { italic_tm : bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_over : bold_end } ⌋ start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT.

{exa}

Consider the session type below

S=&{l1:&{l1:T1,l2:T2,l3:T3},l2:&{l1:T1,l2:T2,l3:T3},l3:T3}.𝑆conditional-setsubscript𝑙1:conditional-setsubscript𝑙1:subscript𝑇1subscript𝑙2subscript𝑇2subscript𝑙3:subscript𝑇3subscript𝑙2conditional-setsubscript𝑙1:subscript𝑇1subscript𝑙2subscript𝑇2subscript𝑙3:subscript𝑇3subscript𝑙3:subscript𝑇3S=\&\{l_{1}:\&\{l_{1}:T_{1},\ l_{2}:T_{2},\ l_{3}:T_{3}\},\;l_{2}:\&\{l_{1}:T_% {1},\ l_{2}:T_{2},\ l_{3}:T_{3}\},\;l_{3}:T_{3}\}.italic_S = & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT } , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT } , italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT } .

Posing 𝒜=&{l1:[]1,l2:[]2,l3:[]3}𝒜conditional-setsubscript𝑙1:superscript1subscript𝑙2superscript2subscript𝑙3:superscript3\mathcal{A}=\&\{l_{1}:[\,]^{1},l_{2}:[\,]^{2},l_{3}:[\,]^{3}\}caligraphic_A = & { italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : [ ] start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , italic_l start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT : [ ] start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT , italic_l start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT : [ ] start_POSTSUPERSCRIPT 3 end_POSTSUPERSCRIPT } we have ℎ𝑜𝑙𝑒𝑠(𝒜)={1,2,3}ℎ𝑜𝑙𝑒𝑠𝒜123\mathit{holes}(\mathcal{A})=\{1,2,3\}italic_holes ( caligraphic_A ) = { 1 , 2 , 3 }. Assuming J={1,2}𝐽12J=\{1,2\}italic_J = { 1 , 2 } and K={3}𝐾3K=\{3\}italic_K = { 3 }, we can rewrite S𝑆Sitalic_S as 𝒜𝒜TjjJJTkkK𝒜superscriptdelimited-⟨⟩𝒜superscriptsubscript𝑇𝑗𝑗𝐽𝐽superscriptsubscript𝑇𝑘𝑘𝐾\mathcal{A}\langle\mathcal{A}\lfloor T_{j}\rfloor^{j\in J}\rangle^{J}\lfloor T% _{k}\rfloor^{k\in K}caligraphic_A ⟨ caligraphic_A ⌊ italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT.

{exa}

Figure 4 shows the partial simulation tree for TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\leq T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT, from Figures 1 and 3 (ignore the dashed edges for now). Notice how the branch leading to the top part of the tree visits only finitely many node labels (see dotted box), however the bottom part of the tree generates infinitely many labels, see the path along the !𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm transitions in the dashed box.

Witness subtrees

Next, we define witness trees which are finite subtrees of a simulation tree which we prove to be successful. The role of the witness subtree is to identify branches that satisfy a certain accumulation pattern. It detects an input context 𝒜𝒜\mathcal{A}caligraphic_A whose holes fall in two categories: (i𝑖iitalic_i) growing holes (indexed by indices in J𝐽Jitalic_J below) which lead to an infinite growth and (ii𝑖𝑖iiitalic_i italic_i) constant holes (indexed by indices in K𝐾Kitalic_K below) which stay stable throughout the simulation game. The definition of witness trees relies on the notion of ancestor of a node n𝑛nitalic_n, which is a node nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT (different from n𝑛nitalic_n) on the path from the root n0subscript𝑛0n_{0}italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT to n𝑛nitalic_n. We illustrate witness trees with Figure 4 and Example 4. {defi}[Witness Tree] A finite tree (N,n0,,λ)𝑁subscript𝑛0𝜆(N,n_{0},\twoheadrightarrow,\lambda)( italic_N , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT , ↠ , italic_λ ) is a witness tree for 𝒜𝒜\mathcal{A}caligraphic_A, such that ℎ𝑜𝑙𝑒𝑠(𝒜)=Iℎ𝑜𝑙𝑒𝑠𝒜𝐼\mathit{holes}(\mathcal{A})=Iitalic_holes ( caligraphic_A ) = italic_I, with KI𝐾𝐼\emptyset\subseteq K\subset I∅ ⊆ italic_K ⊂ italic_I and J=IK𝐽𝐼𝐾J=I\setminus Kitalic_J = italic_I ∖ italic_K, if all the following conditions are satisfied:

  1. (1)

    for all nN𝑛𝑁n\in Nitalic_n ∈ italic_N either λ(n)=(T,𝒜𝒜SjjJJSkkK)𝜆𝑛𝑇superscript𝒜superscriptdelimited-⟨⟩𝒜superscriptsubscript𝑆𝑗𝑗𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda(n)=(T,\mathcal{A}^{\prime}\langle\mathcal{A}\lfloor S_{j}\rfloor^{j\in J% }\rangle^{J}\lfloor S_{k}\rfloor^{k\in K})italic_λ ( italic_n ) = ( italic_T , caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) or
    λ(n)=(T,𝒜𝒜𝒜SjjJJJSkkK)𝜆𝑛𝑇superscript𝒜superscriptdelimited-⟨⟩𝒜superscriptdelimited-⟨⟩𝒜superscriptsubscript𝑆𝑗𝑗𝐽𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda(n)=(T,\mathcal{A}^{\prime}\langle\mathcal{A}\langle\mathcal{A}\lfloor S% _{j}\rfloor^{j\in J}\rangle^{J}\rangle^{J}\lfloor S_{k}\rfloor^{k\in K})italic_λ ( italic_n ) = ( italic_T , caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A ⟨ caligraphic_A ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ), where 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is a reduction of 𝒜𝒜\mathcal{A}caligraphic_A, and it holds that

    • ℎ𝑜𝑙𝑒𝑠(𝒜)Kℎ𝑜𝑙𝑒𝑠superscript𝒜𝐾\mathit{holes}(\mathcal{A}^{\prime})\subseteq Kitalic_holes ( caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ⊆ italic_K implies that n𝑛nitalic_n is a leaf and

    • if λ(n)=(T,𝒜[Si]iI)𝜆𝑛𝑇𝒜superscriptdelimited-[]subscript𝑆𝑖𝑖𝐼\lambda(n)=(T,\mathcal{A}[S_{i}]^{i\in I})italic_λ ( italic_n ) = ( italic_T , caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_i ∈ italic_I end_POSTSUPERSCRIPT ) and n𝑛nitalic_n is not a leaf then 𝗎𝗇𝖿𝗈𝗅𝖽(T)𝗎𝗇𝖿𝗈𝗅𝖽𝑇\mathsf{unfold}(T)sansserif_unfold ( italic_T ) starts with an output selection;

  2. (2)

    each leaf n𝑛nitalic_n of the tree satisfies one of the following conditions:

    1. (a)

      λ(n)=(T,S)𝜆𝑛𝑇𝑆\lambda(n)=(T,S)italic_λ ( italic_n ) = ( italic_T , italic_S ) and n𝑛nitalic_n has an ancestor nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT s.t. λ(n)=(T,S)𝜆superscript𝑛𝑇𝑆\lambda(n^{\prime})=(T,S)italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_T , italic_S )

    2. (b)

      λ(n)=(T,𝒜𝒜SjjJJSkkK)𝜆𝑛𝑇𝒜superscriptdelimited-⟨⟩𝒜superscriptsubscript𝑆𝑗𝑗𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda(n)=(T,\mathcal{A}\langle\mathcal{A}\lfloor S_{j}\rfloor^{j\in J}% \rangle^{J}\lfloor S_{k}\rfloor^{k\in K})italic_λ ( italic_n ) = ( italic_T , caligraphic_A ⟨ caligraphic_A ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) and n𝑛nitalic_n has an ancestor nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT s.t. λ(n)=(T,𝒜[Si]iI)𝜆superscript𝑛𝑇𝒜superscriptdelimited-[]subscript𝑆𝑖𝑖𝐼\lambda(n^{\prime})\!=\!(T,\mathcal{A}[S_{i}]^{i\in I})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_T , caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_i ∈ italic_I end_POSTSUPERSCRIPT )

    3. (c)

      λ(n)=(T,𝒜[Si]iI)𝜆𝑛𝑇𝒜superscriptdelimited-[]subscript𝑆𝑖𝑖𝐼\lambda(n)=(T,\mathcal{A}[S_{i}]^{i\in I})italic_λ ( italic_n ) = ( italic_T , caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_i ∈ italic_I end_POSTSUPERSCRIPT ) and n𝑛nitalic_n has an ancestor nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT s.t. λ(n)=(T,𝒜𝒜SjjJJSkkK)𝜆superscript𝑛𝑇𝒜superscriptdelimited-⟨⟩𝒜superscriptsubscript𝑆𝑗𝑗𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda(n^{\prime})\!=\!(T,\mathcal{A}\langle\mathcal{A}\lfloor S_{j}\rfloor^{% j\in J}\rangle^{J}\lfloor S_{k}\rfloor^{k\in K})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_T , caligraphic_A ⟨ caligraphic_A ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT )

    4. (d)

      λ(n)=(T,𝒜[Sk]kK)𝜆𝑛𝑇superscript𝒜superscriptdelimited-[]subscript𝑆𝑘𝑘superscript𝐾\lambda(n)=(T,\mathcal{A}^{\prime}[S_{k}]^{k\in K^{\prime}})italic_λ ( italic_n ) = ( italic_T , caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT ) where KKsuperscript𝐾𝐾K^{\prime}\subseteq Kitalic_K start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊆ italic_K

    and for all leaves (T,S)𝑇𝑆(T,S)( italic_T , italic_S ) of type (2c) or (2d) TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S holds.

Intuitively Condition (1) says that a witness subtree consists of nodes that are labelled by pairs (T,S)𝑇𝑆(T,S)( italic_T , italic_S ) where S𝑆Sitalic_S contains a fixed context 𝒜𝒜\mathcal{A}caligraphic_A (or a reduction/repetition thereof) whose holes are partitioned in growing holes (J𝐽Jitalic_J) and constant holes (K𝐾Kitalic_K). Whenever all growing holes have been removed from a pair (by reduction of the context) then this means that the pair is labelling a leaf of the tree. In addition, if the initial input is limited to only one instance of 𝒜𝒜\mathcal{A}caligraphic_A, the l.h.s. type starts with an output selection so that this input cannot be consumed in the subtyping simulation game.

Condition 2 says that all leaves of the tree must validate certain conditions from which we can infer that their continuations in the full simulation tree lead to successful branches. Leaves satisfying Condition (2a) straightforwardly lead to successful branches as the subtyping simulation game, starting from the corresponding pair, has been already checked starting from its ancestor having the same label. Leaves satisfying Condition (2b) lead to an infinite but regular “increase” of the types in J𝐽Jitalic_J-indexed holes — following the same pattern of accumulation from their ancestor. The next two kinds of leaves must additionally satisfy the subtyping relation — using witness trees inductively or based on the fact they generate finitely many labels. Leaves satisfying Condition (2c) lead to regular “decrease” of the types in J𝐽Jitalic_J-indexed holes — following the same pattern of reduction from their ancestor. Leaves satisfying Condition (2d) use only constant K𝐾Kitalic_K-indexed holes because, by reduction of the context 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, the growing holes containing the accumulation 𝒜𝒜\mathcal{A}caligraphic_A have been removed.

Remark 12.

Definition 4 is parameterised by an input context 𝒜𝒜\mathcal{A}caligraphic_A. We explain how such contexts can be identified while building a simulation tree in Section 5.

{exa}

In the tree of Figure 4 we highlight two subtrees. The subtree in the dotted box is not a witness subtree because it does not validate Condition (1) of Definition 4, i.e., there is an intermediary node with a label in which the r.h.s type does not contain 𝒜𝒜\mathcal{A}caligraphic_A.

The subtree in the dashed box is a witness subtree with 3 leaves, where the dashed edges represent the ancestor relation, 𝒜=&{𝑡𝑐:[]1,𝑑𝑜𝑛𝑒:[]2}𝒜conditional-set𝑡𝑐:superscript1𝑑𝑜𝑛𝑒superscript2\mathcal{A}=\&\{\mathit{tc}:[\,]^{1},\mathit{done}:[\,]^{2}\}caligraphic_A = & { italic_tc : [ ] start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , italic_done : [ ] start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT }, J={1}𝐽1J=\{1\}italic_J = { 1 } and K={2}𝐾2K=\{2\}italic_K = { 2 }. We comment on the leaves clockwise, starting from (𝐞𝐧𝐝,𝐞𝐧𝐝)𝐞𝐧𝐝𝐞𝐧𝐝(\mathbf{end},\mathbf{end})( bold_end , bold_end ), which satisfies Condition (2d). The next leaf satisfies condition (2c), while the final leaf satisfies Condition (2b).

Algorithm

Given two session types T𝑇Titalic_T and S𝑆Sitalic_S we first check whether S𝑆Sitalic_S is uncontrollable. If this is the case we immediately conclude that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. Otherwise, we proceed in four steps.

  1. S1

    We compute a finite fragment of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ), stopping whenever (i𝑖iitalic_i) we encounter a leaf (successful or not), (ii𝑖𝑖iiitalic_i italic_i) we encounter a node that has an ancestor as defined in Definition 4 (Conditions (2a), (2b), and (2c)), (iii𝑖𝑖𝑖iiiitalic_i italic_i italic_i) or the length of the path from the root of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) to the current node exceeds a bound set to two times the depth of the AST of S𝑆Sitalic_S. This bound allows the algorithm to explore paths that will traverse the super-type at least twice. We have empirically confirmed that it is sufficient for all examples mentioned in Section 5.

  2. S2

    We remove subtrees from the tree produced in S1 corresponding to successful branches of the simulation game which contain finitely many labels. Concretely, we remove each subtree whose each leaf n𝑛nitalic_n is either successful or has an ancestor nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is in the same subtree and λ(n)=λ(n)𝜆𝑛𝜆superscript𝑛\lambda(n)=\lambda(n^{\prime})italic_λ ( italic_n ) = italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

  3. S3

    We extract subtrees from the tree produced in S2 that are potential candidates to be subsequently checked. The extraction of these finite candidate subtrees is done by identifying the forest of subtrees rooted in ancestor nodes which do not have ancestors themselves.

  4. S4

    We check that each of the candidate subtrees from S3 is a witness tree.

If an unsuccessful leaf is found in S1, then the considered session types are not related. In S1, if the generation of the subtree reached the bound before reaching an ancestor or a leaf, then the algorithm is unable to give a decisive verdict, i.e., the result is unknown. Otherwise, if all checks in S4 succeed then the session types are in the fair asynchronous subtyping relation. In all other cases, the result is unknown because a candidate subtree is not a witness.

{exa}

We illustrate the algorithm above with the tree in Figure 4. After S1, we obtain the whole tree in the figure (11 nodes). After S2, all nodes in the dotted boxed are removed. After S3 we obtain the (unique) candidate subtree contained in the dashed box. This subtree is identified as a witness subtree in S4, hence we have TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\operatorname{\leq}T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT.

Soundness of the algorithm

The soundness of our algorithm w.r.t. fair asynchronous session subtyping relies on proving that given a witness tree (N,n0,,λ)𝑁subscript𝑛0𝜆(N,n_{0},\twoheadrightarrow,\lambda)( italic_N , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT , ↠ , italic_λ ) such that λ(n0)=(T,S)𝜆subscript𝑛0𝑇𝑆\lambda(n_{0})=(T,S)italic_λ ( italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT ) = ( italic_T , italic_S ), then TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. We formalize this in Theorem 15 further down below.

The definition of witness tree consider nestings of input contexts 𝒜𝒜\mathcal{A}caligraphic_A. In the proof of Theorem 15 we need the notation 𝒜hSjjJsuperscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽\mathcal{A}^{h}\lfloor S_{j}\rfloor^{j\in J}caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT, to generalize to nestings of input contexts with parametric depth, defined as follows:

  • 𝒜1SjjJsuperscript𝒜1superscriptsubscript𝑆𝑗𝑗𝐽\mathcal{A}^{1}\lfloor S_{j}\rfloor^{j\in J}caligraphic_A start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT is 𝒜SjjJ𝒜superscriptsubscript𝑆𝑗𝑗𝐽\mathcal{A}\lfloor S_{j}\rfloor^{j\in J}caligraphic_A ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT

  • 𝒜hSjjJsuperscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽\mathcal{A}^{h}\lfloor S_{j}\rfloor^{j\in J}caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT is 𝒜𝒜h1SjjJJ𝒜superscriptdelimited-⟨⟩superscript𝒜1superscriptsubscript𝑆𝑗𝑗𝐽𝐽\mathcal{A}\langle\mathcal{A}^{h-1}\lfloor S_{j}\rfloor^{j\in J}\rangle^{J}caligraphic_A ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT, when h>11h>1italic_h > 1.

Given a witness tree for 𝒜𝒜\mathcal{A}caligraphic_A, we define a family of isomorphic trees with labels in which the r.h.s. type has incrementally increased nestings of the input context 𝒜𝒜\mathcal{A}caligraphic_A in the growing holes.

{defi}

[hhitalic_h-th Witness Tree]Given a witness tree 𝒯=(N,n0,,λ)𝒯𝑁subscript𝑛0𝜆\mathcal{T}=(N,n_{0},\twoheadrightarrow,\lambda)caligraphic_T = ( italic_N , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT , ↠ , italic_λ ) for 𝒜𝒜\mathcal{A}caligraphic_A, and h11h\geq 1italic_h ≥ 1, we inductively define 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT as follows:

  • 𝒯1=𝒯superscript𝒯1𝒯\mathcal{T}^{1}=\mathcal{T}caligraphic_T start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT = caligraphic_T;

  • for h>11h>1italic_h > 1, given 𝒯h1=(Nh1,n0h1,h1,λh1)superscript𝒯1superscript𝑁1superscriptsubscript𝑛01superscript1superscript𝜆1\mathcal{T}^{h-1}=(N^{h-1},n_{0}^{h-1},\twoheadrightarrow^{h-1},\lambda^{h-1})caligraphic_T start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT = ( italic_N start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT , ↠ start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT , italic_λ start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT ) we define 𝒯h=(Nh,n0h,h,λh)superscript𝒯superscript𝑁superscriptsubscript𝑛0superscriptsuperscript𝜆\mathcal{T}^{h}=(N^{h},n_{0}^{h},\twoheadrightarrow^{h},\lambda^{h})caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT = ( italic_N start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT , ↠ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT , italic_λ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ) with Nh=Nh1superscript𝑁superscript𝑁1N^{h}=N^{h-1}italic_N start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT = italic_N start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT, n0h=n0h1superscriptsubscript𝑛0superscriptsubscript𝑛01n_{0}^{h}=n_{0}^{h-1}italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT = italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT, h=h1superscriptsuperscript1\twoheadrightarrow^{h}=\twoheadrightarrow^{h-1}↠ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT = ↠ start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT, and
    λh(n)=𝒜𝒜hSjjJJSkkKsuperscript𝜆𝑛superscript𝒜superscriptdelimited-⟨⟩superscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda^{h}(n)=\mathcal{A}^{\prime}\langle\mathcal{A}^{h}\lfloor S_{j}\rfloor^% {j\in J}\rangle^{J}\lfloor S_{k}\rfloor^{k\in K}italic_λ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ( italic_n ) = caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT if λh1(n)=𝒜𝒜h1SjjJJSkkKsuperscript𝜆1𝑛superscript𝒜superscriptdelimited-⟨⟩superscript𝒜1superscriptsubscript𝑆𝑗𝑗𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda^{h-1}(n)=\mathcal{A}^{\prime}\langle\mathcal{A}^{h-1}\lfloor S_{j}% \rfloor^{j\in J}\rangle^{J}\lfloor S_{k}\rfloor^{k\in K}italic_λ start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT ( italic_n ) = caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT.

We now present a preliminary Lemma stating that, given a witness subtree 𝒯𝒯\mathcal{T}caligraphic_T of a simulation tree, all the trees in the family 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT faithfully represent the subtyping simulation game (proof in Appendix A.5).

Lemma 13.

Consider a witness tree 𝒯1=(N1,n01,1,λ1)superscript𝒯1superscript𝑁1superscriptsubscript𝑛01superscript1superscript𝜆1\mathcal{T}^{1}=(N^{1},n_{0}^{1},\twoheadrightarrow^{1},\lambda^{1})caligraphic_T start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT = ( italic_N start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , ↠ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , italic_λ start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT ) contained in a simulation tree. For every h11h\geq 1italic_h ≥ 1, we have that hsuperscript\twoheadrightarrow^{h}↠ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT in 𝒯h=(Nh,n0h,h,λh)superscript𝒯superscript𝑁superscriptsubscript𝑛0superscriptsuperscript𝜆\mathcal{T}^{h}=(N^{h},n_{0}^{h},\twoheadrightarrow^{h},\lambda^{h})caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT = ( italic_N start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT , ↠ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT , italic_λ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ) is compatible with the subtyping simulation game, i.e., nhnsuperscript𝑛superscript𝑛n\twoheadrightarrow^{h}n^{\prime}italic_n ↠ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is present in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT if and only if there exists a simulation tree (M,m0,,λ)𝑀subscript𝑚0𝜆(M,m_{0},\twoheadrightarrow,\lambda)( italic_M , italic_m start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT , ↠ , italic_λ ) including mhmsuperscript𝑚superscript𝑚m\twoheadrightarrow^{h}m^{\prime}italic_m ↠ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with λ(m)=λh(n)𝜆𝑚superscript𝜆𝑛\lambda(m)=\lambda^{h}(n)italic_λ ( italic_m ) = italic_λ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ( italic_n ) and λ(m)=λh(n)𝜆superscript𝑚superscript𝜆superscript𝑛\lambda(m^{\prime})=\lambda^{h}(n^{\prime})italic_λ ( italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = italic_λ start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

We now move to a proposition stating that, given a witness subtree 𝒯𝒯\mathcal{T}caligraphic_T of a simulation tree, we have that all branches in the simulation tree that traverse 𝒯𝒯\mathcal{T}caligraphic_T follows paths also present in the family of trees 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT or in simulation trees 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆\mathit{simtree}(T^{\prime},S^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) where (T,S)superscript𝑇superscript𝑆(T^{\prime},S^{\prime})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) is a leaf of 𝒯𝒯\mathcal{T}caligraphic_T for which we know that TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT (proof in Appendix A.5). In the statement of this proposition we use \twoheadrightarrow\!\!{}^{*}↠ start_FLOATSUPERSCRIPT ∗ end_FLOATSUPERSCRIPT to denote the reflexive and transitive closure of \twoheadrightarrow.

Proposition 14.

Let T𝑇Titalic_T and S𝑆Sitalic_S be two session types with 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)=(N,n0,,λ)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆𝑁subscript𝑛0𝜆\mathit{simtree}(T,S)=(N,n_{0},\twoheadrightarrow,\lambda)italic_simtree ( italic_T , italic_S ) = ( italic_N , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT , ↠ , italic_λ ). If 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) contains a witness tree 𝒯𝒯\mathcal{T}caligraphic_T with root n𝑛nitalic_n, then for every node nNsuperscript𝑛𝑁n^{\prime}\in Nitalic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ italic_N such that nn𝑛superscriptsuperscript𝑛n\twoheadrightarrow\!\!{}^{*}\,n^{\prime}italic_n ↠ start_FLOATSUPERSCRIPT ∗ end_FLOATSUPERSCRIPT italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT we have that λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) is a label present either in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT, for some hhitalic_h, or in 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)=(N,n0,,λ)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆superscript𝑁superscriptsubscript𝑛0superscript𝜆\mathit{simtree}(T^{\prime},S^{\prime})=(N^{\prime},n_{0}^{\prime},% \twoheadrightarrow,\lambda^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_N start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , ↠ , italic_λ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) with TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

We can now present the main result needed to prove the soundness of our algorithm.

Theorem 15.

Let T𝑇Titalic_T and S𝑆Sitalic_S be session types s.t. 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)=(N,n0,,λ)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆𝑁subscript𝑛0𝜆\mathit{simtree}(T,S)=(N,n_{0},\twoheadrightarrow,\lambda)italic_simtree ( italic_T , italic_S ) = ( italic_N , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT , ↠ , italic_λ ). If 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) contains a witness subtree with root n𝑛nitalic_n then for every node nNsuperscript𝑛𝑁n^{\prime}\in Nitalic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ italic_N s.t. nn𝑛superscriptsuperscript𝑛n\twoheadrightarrow\!\!{}^{*}\,n^{\prime}italic_n ↠ start_FLOATSUPERSCRIPT ∗ end_FLOATSUPERSCRIPT italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, either nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is a successful leaf, or there exists n′′superscript𝑛′′n^{\prime\prime}italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT s.t. nn′′superscript𝑛superscript𝑛′′n^{\prime}\twoheadrightarrow{}n^{\prime\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ↠ italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT.

In the light of this last theorem, we can finally conclude that if the candidate subtrees of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒𝑇𝑆\mathit{simtree}(T,S)italic_simtree ( italic_T , italic_S ) identified with the steps S1-3 explained above are also witness subtrees (check done in the step S4), then we have TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S.

5. Implementation

To evaluate our algorithm, we have produced a Haskell implementation of it, which is available on GitHub [tool]. It implements a version of the algorithm presented in Section 4, which internally represents session types as automata (LTS) (see, e.g., [BravettiZ21]). In this context it is also natural to use bisimulation in place of the syntactic equality for session types. These design choices helped us to concretise an implementation of the algorithm in Section  4 and allowed us to implement an optimisation which minimises the input types. We comment on this below.

Using automata internally makes it easier to identify candidate input contexts as we can keep track of states that correspond to the input context computed when applying Case (4) of Definition 3. In particular, we augment each local state in the automata representation of the candidate supertype with two counters: the c𝑐citalic_c-counter keeps track of how many times a state has been used in an input context; the hhitalic_h-counter keeps track of how many times a state has occurred within a hole of an input context. We illustrate this with Figure 5 which depicts the internal data structures our tool manipulates when checking TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\leq T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT from Figures 1 and 3. The state indices of the automata in Figure 5 correspond to the ones in Figure 1 (2nd column) and Figure 3 (3rd column).

The first row of Figure 5 represents the root of the simulation tree, where both session types are in their respective initial state and no transition has been executed. We use state labels of the form nc,hsubscript𝑛𝑐n_{c,h}italic_n start_POSTSUBSCRIPT italic_c , italic_h end_POSTSUBSCRIPT where n𝑛nitalic_n is the original identity of the state, c𝑐citalic_c is the value of the c𝑐citalic_c-counter, and hhitalic_h is the value of the hhitalic_h-counter. The second row depicts the configuration after firing transition !𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm, via Case (4) of Definition 3. While the candidate subtype remains in state 00 (due to a self-loop) the candidate supertype is unfolded with 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(TS)𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽subscriptsuperscript𝑇𝑆\mathsf{selUnfold}(T^{\prime}_{S})sansserif_selUnfold ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ) (Definition 3). The resulting automaton contains an additional state and two transitions. All previously existing states have their hhitalic_h-counter incremented, while the new state has its c𝑐citalic_c-counter incremented. The third row of the figure shows the configuration after firing transition !𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over, using Case (4) of Definition 3 again. In this step, another copy of state 00 is added. Its c𝑐citalic_c-counter is set to 2222 since this state has been used in a context twice; and the hhitalic_h-counters of all other states are incremented.

Using this representation, we construct a candidate input context by building a tree whose root is a state qc,hsubscript𝑞𝑐q_{c,h}italic_q start_POSTSUBSCRIPT italic_c , italic_h end_POSTSUBSCRIPT such that c>1𝑐1c>1italic_c > 1. The nodes of the tree are taken from the states reachable from qc,hsubscript𝑞𝑐q_{c,h}italic_q start_POSTSUBSCRIPT italic_c , italic_h end_POSTSUBSCRIPT, stopping when a state qc,hsubscriptsuperscript𝑞superscript𝑐superscriptq^{\prime}_{c^{\prime},h^{\prime}}italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_h start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT such that c<csuperscript𝑐𝑐c^{\prime}<citalic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT < italic_c is found. A leaf qc,hsubscriptsuperscript𝑞superscript𝑐superscriptq^{\prime}_{c^{\prime},h^{\prime}}italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_h start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT becomes a hole of the input context. The hole is a constant (K𝐾Kitalic_K) hole when h=csuperscript𝑐h^{\prime}=citalic_h start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = italic_c, and growing (J𝐽Jitalic_J) otherwise. Given this strategy and the configurations in Figure 5, we successfully identify the context 𝒜=&{𝑡𝑐:[]1,𝑑𝑜𝑛𝑒:[]2}𝒜conditional-set𝑡𝑐:superscript1𝑑𝑜𝑛𝑒superscript2\mathcal{A}=\&\{\mathit{tc}:[\,]^{1},\mathit{done}:[\,]^{2}\}caligraphic_A = & { italic_tc : [ ] start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT , italic_done : [ ] start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT } with J={1}𝐽1J=\{1\}italic_J = { 1 } and K={2}𝐾2K=\{2\}italic_K = { 2 }.

Thanks to our automata representation, it is also possible to minimise (up-to bisimulation) each session-type automaton before performing Steps S1-S4. Concretely our tool accepts an optional command-line flag that turns on the minimisation of each session type after it has been transformed into an automaton. We discuss the benefits of this optimisation in the next section.

Last transition   State of TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT Representation of TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT
ϵitalic-ϵ\epsilonitalic_ϵ 00 00,0subscript0000_{0,0}0 start_POSTSUBSCRIPT 0 , 0 end_POSTSUBSCRIPT10,0subscript1001_{0,0}1 start_POSTSUBSCRIPT 0 , 0 end_POSTSUBSCRIPT20,0subscript2002_{0,0}2 start_POSTSUBSCRIPT 0 , 0 end_POSTSUBSCRIPT30,0subscript3003_{0,0}3 start_POSTSUBSCRIPT 0 , 0 end_POSTSUBSCRIPT40,0subscript4004_{0,0}4 start_POSTSUBSCRIPT 0 , 0 end_POSTSUBSCRIPT50,0subscript5005_{0,0}5 start_POSTSUBSCRIPT 0 , 0 end_POSTSUBSCRIPT?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over
!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm 00 00,1subscript0010_{0,1}0 start_POSTSUBSCRIPT 0 , 1 end_POSTSUBSCRIPT10,1subscript1011_{0,1}1 start_POSTSUBSCRIPT 0 , 1 end_POSTSUBSCRIPT20,1subscript2012_{0,1}2 start_POSTSUBSCRIPT 0 , 1 end_POSTSUBSCRIPT30,1subscript3013_{0,1}3 start_POSTSUBSCRIPT 0 , 1 end_POSTSUBSCRIPT40,1subscript4014_{0,1}4 start_POSTSUBSCRIPT 0 , 1 end_POSTSUBSCRIPT50,1subscript5015_{0,1}5 start_POSTSUBSCRIPT 0 , 1 end_POSTSUBSCRIPT01,0subscript0100_{1,0}0 start_POSTSUBSCRIPT 1 , 0 end_POSTSUBSCRIPT?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done!𝑡𝑚!{\mathit{\mathit{tm}}}! italic_tm!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over
!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over 1111 00,2subscript0020_{0,2}0 start_POSTSUBSCRIPT 0 , 2 end_POSTSUBSCRIPT10,2subscript1021_{0,2}1 start_POSTSUBSCRIPT 0 , 2 end_POSTSUBSCRIPT20,2subscript2022_{0,2}2 start_POSTSUBSCRIPT 0 , 2 end_POSTSUBSCRIPT30,2subscript3023_{0,2}3 start_POSTSUBSCRIPT 0 , 2 end_POSTSUBSCRIPT40,2subscript4024_{0,2}4 start_POSTSUBSCRIPT 0 , 2 end_POSTSUBSCRIPT50,2subscript5025_{0,2}5 start_POSTSUBSCRIPT 0 , 2 end_POSTSUBSCRIPT01,1subscript0110_{1,1}0 start_POSTSUBSCRIPT 1 , 1 end_POSTSUBSCRIPT02,0subscript0200_{2,0}0 start_POSTSUBSCRIPT 2 , 0 end_POSTSUBSCRIPT?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑡𝑐?𝑡𝑐?\mathit{\mathit{tc}}? italic_tc?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done
Figure 5. Internal representation of the simulation tree for TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\leq T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT (fragment).

We have run our tool on a dozen of examples handcrafted to test the limits of our algorithm (inc. the examples discussed in this paper), as well as on the 174 tests taken from [BCLYZ19]. All of these tests terminate under a second.

Additionally, for debugging and illustration purposes, the tool can optionally generate graphical representations of the subtyping simulation game and of witness trees.

6. Empirical Evaluation on Synthetic Benchmarks

To evaluate the cost of our algorithm and its implementation, wrt. runtime and memory usage, we have performed an empirical evaluation based on a family of pairs of sub/supertype of increasing sizes. We perform our evaluation with and without our minimisation-based optimisation and discuss the results.

Experimental setup

The family of types we consider is based on variants from our spacecraft example: the subtype is based on variants of TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT in Figure 1, while the supertype is based on variants of TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT in Figure 3. The shape and size of each variant is determined by three parameters which respectively affect the number of choices in branches (branching width), the number of inputs that can be accumulated in the supertype (input depth), and the number of choices in selections (selection width).

𝑇𝑒𝑠𝑡(n,m,k)=TL(n,k)TR(n,m,k)TL(n,k)=μ𝐭.{𝑡𝑚i:𝐭,𝑜𝑣𝑒𝑟:𝑇𝐵𝑟𝑎𝑛𝐿(n)}1ikTR(n,m,k)=μ𝐭.𝑇𝐵𝑟𝑎𝑛(n,m,k)𝑇𝐵𝑟𝑎𝑛(n,m,k)={&{𝑡𝑐i:𝑇𝐵𝑟𝑎𝑛(n,m1,k),𝑑𝑜𝑛𝑒:𝑇𝑆𝑒𝑙𝐿(k)}1inif m>0&{𝑡𝑐i:𝑇𝑆𝑒𝑙(n,k),𝑑𝑜𝑛𝑒:𝑇𝑆𝑒𝑙𝐿(k)}1inotherwise𝑇𝑆𝑒𝑙(n,k)={𝑡𝑚i:𝐭,𝑜𝑣𝑒𝑟:𝑇𝐵𝑟𝑎𝑛𝐿(n)}1ik𝑇𝐵𝑟𝑎𝑛𝐿(n)=μ𝐭.&{𝑡𝑐i:𝐭,𝑑𝑜𝑛𝑒:𝐞𝐧𝐝}1in𝑇𝑆𝑒𝑙𝐿(k)=μ𝐭′′.{𝑡𝑚i:𝐭′′,𝑜𝑣𝑒𝑟:𝐞𝐧𝐝}1ik𝑇𝑒𝑠𝑡𝑛𝑚𝑘subscript𝑇L𝑛𝑘subscript𝑇R𝑛𝑚𝑘subscript𝑇L𝑛𝑘formulae-sequence𝜇𝐭direct-sumsubscriptconditional-setsubscript𝑡𝑚𝑖:𝐭𝑜𝑣𝑒𝑟𝑇𝐵𝑟𝑎𝑛𝐿𝑛1𝑖𝑘subscript𝑇R𝑛𝑚𝑘formulae-sequence𝜇𝐭𝑇𝐵𝑟𝑎𝑛𝑛𝑚𝑘𝑇𝐵𝑟𝑎𝑛𝑛𝑚𝑘casessubscriptconditional-setsubscript𝑡𝑐𝑖:𝑇𝐵𝑟𝑎𝑛𝑛𝑚1𝑘𝑑𝑜𝑛𝑒𝑇𝑆𝑒𝑙𝐿𝑘1𝑖𝑛if 𝑚0subscriptconditional-setsubscript𝑡𝑐𝑖:𝑇𝑆𝑒𝑙𝑛𝑘𝑑𝑜𝑛𝑒𝑇𝑆𝑒𝑙𝐿𝑘1𝑖𝑛otherwise𝑇𝑆𝑒𝑙𝑛𝑘direct-sumsubscriptconditional-setsubscript𝑡𝑚𝑖:𝐭𝑜𝑣𝑒𝑟𝑇𝐵𝑟𝑎𝑛𝐿𝑛1𝑖𝑘𝑇𝐵𝑟𝑎𝑛𝐿𝑛formulae-sequence𝜇superscript𝐭subscriptconditional-setsubscript𝑡𝑐𝑖:superscript𝐭𝑑𝑜𝑛𝑒𝐞𝐧𝐝1𝑖𝑛𝑇𝑆𝑒𝑙𝐿𝑘formulae-sequence𝜇superscript𝐭′′direct-sumsubscriptconditional-setsubscript𝑡𝑚𝑖:superscript𝐭′′𝑜𝑣𝑒𝑟𝐞𝐧𝐝1𝑖𝑘\begin{array}[]{lcl}\mathit{Test}(n,m,k)&=&T_{\textit{L}}({n,k)}\leq T_{% \textit{R}}(n,m,k)\\[5.69046pt] T_{\textit{L}}({n,k)}&=&\mu\mathbf{t}.\oplus\{{\mathit{tm}}_{i}:{\mathbf{t}},% \ \mathit{over}:\mathit{TBranL}({n})\}_{1\leq i\leq k}\\[5.69046pt] T_{\textit{R}}(n,m,k)&=&\mu\mathbf{t}.\mathit{TBran}({n,m,k})\\[5.69046pt] \mathit{TBran}({n,m,k})&=&\begin{cases}\&\{{\mathit{tc}}_{i}:{\mathit{TBran}({% n,m{-}1,k})},\ \mathit{done}:\mathit{TSelL}({k})\}_{1\leq i\leq n}&\text{if }m% >0\\ \&\{{\mathit{tc}}_{i}:{\mathit{TSel}({n,k})},\ \mathit{done}:\mathit{TSelL}({k% })\}_{1\leq i\leq n}&\text{otherwise}\end{cases}\\[5.69046pt] \mathit{TSel}({n,k})&=&\oplus\{{\mathit{tm}}_{i}:{\mathbf{t}},\ \mathit{over}:% \mathit{TBranL}({n})\}_{1\leq i\leq k}\\[5.69046pt] \mathit{TBranL}({n})&=&\mu\mathbf{t^{\prime}}.\&\{{\mathit{tc}}_{i}:{\mathbf{t% }^{\prime}},\ \mathit{done}:\mathbf{end}\}_{1\leq i\leq n}\\[5.69046pt] \mathit{TSelL}({k})&=&\mu\mathbf{t^{\prime\prime}}.\oplus\{{\mathit{tm}}_{i}:{% \mathbf{t}^{\prime\prime}},\ \mathit{over}:\mathbf{end}\}_{1\leq i\leq k}\end{array}start_ARRAY start_ROW start_CELL italic_Test ( italic_n , italic_m , italic_k ) end_CELL start_CELL = end_CELL start_CELL italic_T start_POSTSUBSCRIPT L end_POSTSUBSCRIPT ( italic_n , italic_k ) ≤ italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( italic_n , italic_m , italic_k ) end_CELL end_ROW start_ROW start_CELL italic_T start_POSTSUBSCRIPT L end_POSTSUBSCRIPT ( italic_n , italic_k ) end_CELL start_CELL = end_CELL start_CELL italic_μ bold_t . ⊕ { italic_tm start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : bold_t , italic_over : italic_TBranL ( italic_n ) } start_POSTSUBSCRIPT 1 ≤ italic_i ≤ italic_k end_POSTSUBSCRIPT end_CELL end_ROW start_ROW start_CELL italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( italic_n , italic_m , italic_k ) end_CELL start_CELL = end_CELL start_CELL italic_μ bold_t . italic_TBran ( italic_n , italic_m , italic_k ) end_CELL end_ROW start_ROW start_CELL italic_TBran ( italic_n , italic_m , italic_k ) end_CELL start_CELL = end_CELL start_CELL { start_ROW start_CELL & { italic_tc start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_TBran ( italic_n , italic_m - 1 , italic_k ) , italic_done : italic_TSelL ( italic_k ) } start_POSTSUBSCRIPT 1 ≤ italic_i ≤ italic_n end_POSTSUBSCRIPT end_CELL start_CELL if italic_m > 0 end_CELL end_ROW start_ROW start_CELL & { italic_tc start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_TSel ( italic_n , italic_k ) , italic_done : italic_TSelL ( italic_k ) } start_POSTSUBSCRIPT 1 ≤ italic_i ≤ italic_n end_POSTSUBSCRIPT end_CELL start_CELL otherwise end_CELL end_ROW end_CELL end_ROW start_ROW start_CELL italic_TSel ( italic_n , italic_k ) end_CELL start_CELL = end_CELL start_CELL ⊕ { italic_tm start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : bold_t , italic_over : italic_TBranL ( italic_n ) } start_POSTSUBSCRIPT 1 ≤ italic_i ≤ italic_k end_POSTSUBSCRIPT end_CELL end_ROW start_ROW start_CELL italic_TBranL ( italic_n ) end_CELL start_CELL = end_CELL start_CELL italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . & { italic_tc start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_done : bold_end } start_POSTSUBSCRIPT 1 ≤ italic_i ≤ italic_n end_POSTSUBSCRIPT end_CELL end_ROW start_ROW start_CELL italic_TSelL ( italic_k ) end_CELL start_CELL = end_CELL start_CELL italic_μ bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT . ⊕ { italic_tm start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_over : bold_end } start_POSTSUBSCRIPT 1 ≤ italic_i ≤ italic_k end_POSTSUBSCRIPT end_CELL end_ROW end_ARRAY
Figure 6. Generation of parameterised sub-type/super-type pairs. Function TR(n,m,k)subscript𝑇R𝑛𝑚𝑘T_{\textit{R}}(n,m,k)italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( italic_n , italic_m , italic_k ) is the super-type and TL(n,k)subscript𝑇L𝑛𝑘T_{\textit{L}}({n,k)}italic_T start_POSTSUBSCRIPT L end_POSTSUBSCRIPT ( italic_n , italic_k ) is the sub-type, where n𝑛nitalic_n is the branching width (the number of messages the type can receive at a given point), m𝑚mitalic_m is the branching depth (the number of messages the type can receive consecutively), and k𝑘kitalic_k is the selection width (the number of messages the type can send at a given point).

Given values n𝑛nitalic_n, m𝑚mitalic_m, and k𝑘kitalic_k for each of these parameters, we generate a subtyping problem 𝑇𝑒𝑠𝑡(n,m,k)𝑇𝑒𝑠𝑡𝑛𝑚𝑘\mathit{Test}(n,m,k)italic_Test ( italic_n , italic_m , italic_k ) as described in Figure 6. We assume that n1𝑛1n\geq 1italic_n ≥ 1, m0𝑚0m\geq 0italic_m ≥ 0, and k1𝑘1k\geq 1italic_k ≥ 1 — the branching/selection parameters need to provide at least one branch, while input depth could be zero (no anticipation). Each test applies our algorithm to verify that TL(n,k)subscript𝑇L𝑛𝑘T_{\textit{L}}({n,k)}italic_T start_POSTSUBSCRIPT L end_POSTSUBSCRIPT ( italic_n , italic_k ) is a fair asynchronous subtype of TR(n,m,k)subscript𝑇R𝑛𝑚𝑘T_{\textit{R}}(n,m,k)italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( italic_n , italic_m , italic_k ) (by construction the test always succeeds).

We describe Figure 6 in more details. The subtype TL(n,k)subscript𝑇L𝑛𝑘T_{\textit{L}}({n,k)}italic_T start_POSTSUBSCRIPT L end_POSTSUBSCRIPT ( italic_n , italic_k ) only depends on two parameters: branching width (n𝑛nitalic_n) and selection width (k𝑘kitalic_k). It is similar to TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT in Figure 1 except that it can send (resp. receive) different telemetry (resp. telecommand) messages. It is a recursive type that immediately chooses between sending one of the k𝑘kitalic_k telemetries (𝑡𝑚isubscript𝑡𝑚𝑖\mathit{tm}_{i}italic_tm start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT) then recurse, or send a termination signal (𝑜𝑣𝑒𝑟𝑜𝑣𝑒𝑟\mathit{over}italic_over). In the latter case, the behaviour continues with 𝑇𝐵𝑟𝑎𝑛𝐿(n)𝑇𝐵𝑟𝑎𝑛𝐿𝑛\mathit{TBranL}({n})italic_TBranL ( italic_n ), i.e., another recursive definition followed by a branching construct where the type expects to receive either one of the n𝑛nitalic_n telecommands (𝑡𝑐isubscript𝑡𝑐𝑖\mathit{tc}_{i}italic_tc start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT) then recurse, or receive the termination signal 𝑑𝑜𝑛𝑒𝑑𝑜𝑛𝑒\mathit{done}italic_done.

The supertype TR(n,m,k)subscript𝑇R𝑛𝑚𝑘T_{\textit{R}}(n,m,k)italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( italic_n , italic_m , italic_k ) depends on three parameters: branching width (n𝑛nitalic_n), input depth (m𝑚mitalic_m), and selection width (k𝑘kitalic_k). This type is similar to TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT in Figure 3 but can send (resp. receive) different telemetry (resp. telecommand) messages and allows the reception of m𝑚mitalic_m telecommands to precede the emission of a telemetry message. TR(n,m,k)subscript𝑇R𝑛𝑚𝑘T_{\textit{R}}(n,m,k)italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( italic_n , italic_m , italic_k ) relies on four additional definitions. 𝑇𝐵𝑟𝑎𝑛(n,m,k)𝑇𝐵𝑟𝑎𝑛𝑛𝑚𝑘\mathit{TBran}({n,m,k})italic_TBran ( italic_n , italic_m , italic_k ) encodes the sequence of m+1𝑚1m+1italic_m + 1 inputs that can precede the emission of telemetries. 𝑇𝑆𝑒𝑙(n,k)𝑇𝑆𝑒𝑙𝑛𝑘\mathit{TSel}({n,k})italic_TSel ( italic_n , italic_k ) performs the selections that precede the final series of inputs in 𝑇𝐵𝑟𝑎𝑛𝐿(n)𝑇𝐵𝑟𝑎𝑛𝐿𝑛\mathit{TBranL}({n})italic_TBranL ( italic_n ). 𝑇𝑆𝑒𝑙𝐿(k)𝑇𝑆𝑒𝑙𝐿𝑘\mathit{TSelL}({k})italic_TSelL ( italic_k ) performs the final series of outputs.

0011112222{!𝑡𝑚1,!𝑡𝑚2,!𝑡𝑚3,!𝑡𝑚4}\{!{\mathit{\mathit{tm}}}_{1},!{\mathit{\mathit{tm}}}_{2},!{\mathit{\mathit{tm% }}}_{3},!{\mathit{\mathit{tm}}}_{4}\}{ ! italic_tm start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 4 end_POSTSUBSCRIPT }!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done{?𝑡𝑐1,?𝑡𝑐2}?subscript𝑡𝑐1?subscript𝑡𝑐2\{?\mathit{\mathit{tc}}_{1},?\mathit{\mathit{tc}}_{2}\}{ ? italic_tc start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ? italic_tc start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT }
00subscript000_{0}0 start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT01subscript010_{1}0 start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT02subscript020_{2}0 start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT03subscript030_{3}0 start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT4444111122223,5353,53 , 5{?𝑡𝑐1,?𝑡𝑐2}?subscript𝑡𝑐1?subscript𝑡𝑐2\{?\mathit{\mathit{tc}}_{1},?\mathit{\mathit{tc}}_{2}\}{ ? italic_tc start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ? italic_tc start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT }{?𝑡𝑐1,?𝑡𝑐2}?subscript𝑡𝑐1?subscript𝑡𝑐2\{?\mathit{\mathit{tc}}_{1},?\mathit{\mathit{tc}}_{2}\}{ ? italic_tc start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ? italic_tc start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT }{?𝑡𝑐1,?𝑡𝑐2}?subscript𝑡𝑐1?subscript𝑡𝑐2\{?\mathit{\mathit{tc}}_{1},?\mathit{\mathit{tc}}_{2}\}{ ? italic_tc start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ? italic_tc start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT }{?𝑡𝑐1,?𝑡𝑐2}?subscript𝑡𝑐1?subscript𝑡𝑐2\{?\mathit{\mathit{tc}}_{1},?\mathit{\mathit{tc}}_{2}\}{ ? italic_tc start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ? italic_tc start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT }?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done{!𝑡𝑚1,!𝑡𝑚2,!𝑡𝑚3,!𝑡𝑚4}\{!{\mathit{\mathit{tm}}}_{1},!{\mathit{\mathit{tm}}}_{2},!{\mathit{\mathit{tm% }}}_{3},!{\mathit{\mathit{tm}}}_{4}\}{ ! italic_tm start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 4 end_POSTSUBSCRIPT }{!𝑡𝑚1,!𝑡𝑚2,!𝑡𝑚3,!𝑡𝑚4}\{!{\mathit{\mathit{tm}}}_{1},!{\mathit{\mathit{tm}}}_{2},!{\mathit{\mathit{tm% }}}_{3},!{\mathit{\mathit{tm}}}_{4}\}{ ! italic_tm start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 3 end_POSTSUBSCRIPT , ! italic_tm start_POSTSUBSCRIPT 4 end_POSTSUBSCRIPT }!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over!𝑜𝑣𝑒𝑟!{\mathit{\mathit{over}}}! italic_over?𝑑𝑜𝑛𝑒?𝑑𝑜𝑛𝑒?\mathit{\mathit{done}}? italic_done{?𝑡𝑐1,?𝑡𝑐2}?subscript𝑡𝑐1?subscript𝑡𝑐2\{?\mathit{\mathit{tc}}_{1},?\mathit{\mathit{tc}}_{2}\}{ ? italic_tc start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , ? italic_tc start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT }
Figure 7. Minimised versions of TL(2,4)subscript𝑇L24T_{\textit{L}}({2,4)}italic_T start_POSTSUBSCRIPT L end_POSTSUBSCRIPT ( 2 , 4 ) (subtype, left) and TR(2,3,4)subscript𝑇R234T_{\textit{R}}(2,3,4)italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( 2 , 3 , 4 ) (supertype, right).

Figure 7 gives a graphical representation of the session-type automata generated by the definitions in Figure 6 after minimisation up to bisimulation. The figure shows a subtype (left) that can send four different 𝑡𝑚isubscript𝑡𝑚𝑖\mathit{tm}_{i}italic_tm start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT messages (k=4)k=4)italic_k = 4 ), then can receive two different 𝑡𝑐isubscript𝑡𝑐𝑖\mathit{tc}_{i}italic_tc start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT messages (n=2𝑛2n=2italic_n = 2). The state labels correspond to the ones of TSsubscript𝑇𝑆T_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT in Figure 1.

The supertype (right) is more complex. It can also send four different 𝑡𝑚isubscript𝑡𝑚𝑖\mathit{tm}_{i}italic_tm start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT messages (k=4)k=4)italic_k = 4 ), and receive two different 𝑡𝑐isubscript𝑡𝑐𝑖\mathit{tc}_{i}italic_tc start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT messages (n=2𝑛2n=2italic_n = 2). Additionally, it may postpone the emission of telemetries and receive up to 4444 telecommands first (m+1=4𝑚14m+1=4italic_m + 1 = 4). The state labels correspond to the ones of TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT in Figure 3. Note that because of minimisation the two final states of TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT are merged into their 3,5353,53 , 5 counterpart in Figure 7. Since the emission of 𝑡𝑚isubscript𝑡𝑚𝑖\mathit{tm}_{i}italic_tm start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT in TR(2,3,4)subscript𝑇R234T_{\textit{R}}(2,3,4)italic_T start_POSTSUBSCRIPT R end_POSTSUBSCRIPT ( 2 , 3 , 4 ) is further postponed compared to TSsubscriptsuperscript𝑇𝑆T^{\prime}_{S}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT, we also obtain several variants of state 00, labelled by 0isubscript0𝑖0_{i}0 start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT and highlighted in gray in Figure 7.

Refer to caption
Refer to caption
Figure 8. Increasing branching width, without (left) and with minimisation (right)
Refer to caption
Refer to caption
Figure 9. Increasing input depth, without (left) and with minimisation (right)
Refer to caption
Refer to caption
Figure 10. Increasing selection width, without (left) and with minimisation (right)

Experimental results

Figures 1010, and 10 give the results of running the implementation of our algorithm on increasingly large instances of the subtyping problem 𝑇𝑒𝑠𝑡(n,m,k)𝑇𝑒𝑠𝑡𝑛𝑚𝑘\mathit{Test}(n,m,k)italic_Test ( italic_n , italic_m , italic_k ). Each figure shows the runtime (larger data points in blue, left y-axis) and peak memory usage (smaller data points in red, right y-axis) for each instance of the problem. Each figure includes two x-axes: the bottom one represents the number of transitions in the automata representation of the candidate supertype (which we consider a good measure of the size of the subtyping problem); the top one represents the value of the variable parameter for each experiment (e.g., branching with). Plots on the left show the result without minimisation, plots on the right show results using minimisation up to bisimulation. Each figure depicts 20 data points unless our implementation timed out (more than 300 seconds). The yellow curve highlights the runtime trend. It is computed using SciPy’s curve_fit function.

All the benchmarks in this paper were run on a MacBook Pro with an Intel i5 CPU with 16GB RAM running macOS 13.4. The time was measured by taking the difference between the system clock before and after our tool was invoked. The memory usage refers to the maximum resident set size as reported by the /usr/bin/time -l command. Each test was ran 3 times, the plots report the average time (resp. memory) measurements. All our test data and infrastructure are available on our GitHub repository [tool].

Figure 10 shows the result of checking 𝑇𝑒𝑠𝑡(n,1,1)𝑇𝑒𝑠𝑡𝑛11\mathit{Test}(n,1,1)italic_Test ( italic_n , 1 , 1 ), with n𝑛nitalic_n (branching width) increasing by step of 1111, from 1111 to 20202020. The left-hand side plot shows that the tool quickly runs out of resource without optimisation: only n{1,2,3}𝑛123n\in\{1,2,3\}italic_n ∈ { 1 , 2 , 3 } terminate in reasonable time. While the asymptotic cost of the algorithm with minimised automata is still exponential, the tool can deal with much larger input using this optimisation as show on the right.

Figure 10 shows the result of checking 𝑇𝑒𝑠𝑡(1,m,1)𝑇𝑒𝑠𝑡1𝑚1\mathit{Test}(1,m,1)italic_Test ( 1 , italic_m , 1 ), with m𝑚mitalic_m (input depth) increasing by step of 3333, from 1111 to 58585858 (20202020 data points). Observe that minimisation nearly halves the number of transitions in the candidate supertypes. As a consequence, the version of the tool that minimises its input before applying the subtyping algorithm runs much faster and uses much less memory than its non-optimised counterpart.

Figure 10 shows the result of checking 𝑇𝑒𝑠𝑡(1,1,k)𝑇𝑒𝑠𝑡11𝑘\mathit{Test}(1,1,k)italic_Test ( 1 , 1 , italic_k ), with k𝑘kitalic_k (selection width) increasing by step of 3333, from 1111 to 58585858 (20202020 data points). In this case minimisation has a lesser effect on the number of transitions in the candidate supertypes, but it has still a significant effect on runtime, e.g., the largest problem takes 20s on the minimised automata and 37s on the non-minimised ones.

7. Related and Future Work

Related work

The relationship between refinement and subtyping in the context of synchronous session types has been thoroughly investigated both for binary and multiparty session types. For instance, Bernardi and Hennessy [BernardiH16] establish a correspondence between binary session subtyping and an observational preorder on session types interpreted as contracts. A similar result has been obtained in the context of multiparty session types by Severi and Dezani-Ciancaglini [SeveriD19], where the subtyping is dubbed structural preorder, while the refinement is named observational preorder. Concerning asynchronous communication we can mention previous works on refinement for asynchronous communication by some of the authors of this paper. The work in [wsfm08] also considers fair compliance, however here we consider binary (instead of multiparty) communication and we use a unique input queue for all incoming messages instead of distinct named input channels. Moreover, in the present paper we provide a sound characterisation of fair refinement using coinductive subtyping and provide a sound algorithm and its implementation. In [sefm19, BravettiZ21] the asynchronous subtyping of [MY15] is used to characterise refinement for a notion of correct composition based on the impossibility to reach a deadlock, instead of the possibility to reach a final successful configuration as done in the present paper. The refinement from [sefm19] does not support examples such as those in Figure 1.

Concerning fairness in the context of session types, Padovani studied a notion of fair subtyping for synchronous multi-party session types in [Padovani16]. This work notably considers the notion of viability which corresponds, in the synchronous multiparty setting, to our notion of controllability. We use the term controllability instead of viability following the tradition of service contract theories like those based on Petri nets [Loh08, Wei08] or process calculi [BZ09a]. Compared to [Padovani16], asynchronous communication makes it much more involved to prove soundness and completeness of the decidable characterisation of controllability, as we do in this paper. Indeed in the asynchronous case, transition systems arising from the communication of two types are, in general, infinite state (due to unbounded queues), while they are always finite state in the synchronous case. Fair refinement in [Padovani16] is characterised by defining a coinductive relation on normal form of types, obtained by removing inputs leading to uncontrollable continuations. Instead of using normal forms, we remove these inputs during the asynchronous subtyping check. A limited form of variance on output is also admitted in [Padovani16]. Covariance between the outputs of a subtype and those of a supertype is possible when the additional branches in the supertype are not needed to have compliance with potential partners. In [Padovani16] this check is made possible by exploiting a difference operation [Padovani16, Definition 3.15] on types, which synthesises a new type representing branches of one type that are absent in the other. We observe that the same approach cannot work to introduce variance on outputs in an asynchronous setting. Indeed the interplay between output anticipation and recursion could generate differences in the branches of a subtype and a supertype that cannot be statically represented by a (finite) session type.

Padovani also studied an alternative notion of fair synchronous subtyping in [Padovani13]. Although the contribution of that paper refers to session types, the formal framework therein seems to deviate from the usual session type approach. In particular, it considers shared channel communication instead of binary channels: when a partner emits a message, it is possible to have a race among several potential receivers for consuming it. As a consequence of this alternative semantics, the subtyping in [Padovani13] does not admit variance on input. Another difference with respect to session type literature is the notion of success among interacting sessions: a composition of session is successful if at least one participant reaches an internal successful state. This approach has commonalities with testing [DH84], where only the test composed with the system under test is expected to succeed, but differs from the typical notion of success considered for session types. In [Barbanerad10, BernardiH16] (resp. [MariangiolaPreciness]) it was proved that the Gay-Hole synchronous session subtyping (resp. orphan message free asynchronous subtyping) coincides with refinement induced by a successful termination notion requiring interacting processes to be both in the 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end state (with empty buffers, in the asynchronous case).

More recently, van Glabbeek et al. [GlabbeekHH21] introduce a type system for multiparty sessions that assumes fairness. Nevertheless, the notion of fairness used in that paper is different with respect to the notion considered by Padovani [Padovani16] (in the synchronous case) and in this paper (in the asynchronous case). In fact, in [GlabbeekHH21] weak fairness is considered, consisting of a minimal fairness assumption that “guarantees only that concurrent transitions cannot prevent each other from happening”. On the other hand, Padovani [Padovani16] and ourselves consider a stronger notion of fairness, namely, according to the terminology in [GlabbeekH19], we consider the composition of two session types correct if their successful termination is a liveness property which holds under the assumption of full fairness. In [GlabbeekH19] it is proved that, for finite state transition systems, full fairness collapses to strong fairness of transitions, i.e., a transition which is (relentlessly) enabled infinitely many times during a computation, it is also executed infinitely often in such computation. Session types are finite states, but we consider asynchronous communication via unbounded FIFO buffers, hence our transition system (Definition 2.2) describing the composition of two session types is not finite because buffers can store an unbounded amount of messages. On the contrary, in the context of synchronous communication the transition system describing the composition of two session types is finite state, hence the above correspondence result between full fairness and strong fairness applies. A strong fair session subtyping has been recently used in a type system that guarantees fair termination of sessions for a π𝜋\piitalic_π-calculus like language with binary sessions [CicconeP22]. The subtype defined in that paper differs from previous strong fair subtypings because it also deals with higher-order types (useful to type process languages including primitives for session creation and delegation) and because it is only sound but not complete w.r.t. fair session type refinement. More precisely, it is complete only for bounded processes and it does not capture subtypes like those discussed in Example 3, where the supertype has an uncontrollable (infinite) branch.

Several variants of asynchronous session subtyping have been proposed in [ESOP09, MariangiolaPreciness, CDY2014, MY15, GhilezanPPSY21] and further studied in our earlier work [BravettiCZ17, BravettiCLYZ21, sefm19, BCLYZ19]. All these variants have been shown to be undecidable [BCZ18, LY17, BravettiCZ17]. Moreover, all these subtyping relations are (implicitly) based on an unfair notion of compliance. Some of these papers consider binary session types [MariangiolaPreciness, CDY2014, MY15] as we do in this paper. An interesting technical difference with these papers is that they use finite input contexts (i.e. without recursion) while we also consider infinite input contexts which may contain recursion — this is necessary to obtain TGTGsubscriptsuperscript𝑇𝐺subscript𝑇𝐺T^{\prime}_{G}\operatorname{\leq}T_{G}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT ≤ italic_T start_POSTSUBSCRIPT italic_G end_POSTSUBSCRIPT and TSTSsubscript𝑇𝑆subscriptsuperscript𝑇𝑆T_{S}\operatorname{\leq}T^{\prime}_{S}italic_T start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ≤ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT (see Figures 1 and 3). Moreover, the papers [MariangiolaPreciness, CDY2014] impose additional constraints in the definition of asynchronous subtyping to guarantee absence of orphan-messages. Such constraints require the subtype not to have output loops whenever an output anticipation is performed, thus guaranteeing that at least one input is performed in all possible paths. In this paper, absence of orphan messages between compatible types is guaranteed as successful termination is enforced under the assumption of full-fairness. Notice that not imposing this orphan-message-free constraint is consistent with our recursive input contexts that allows for input loops in the supertype whenever an output anticipation is performed. The other papers [ESOP09, GhilezanPPSY21] consider asynchronous subtyping for multiparty session types. In the binary case, a subtype can only anticipate (under some specific conditions) outputs w.r.t input. In the multiparty context additional differences are allowed, for instance, a subtype can anticipate also an input w.r.t. other inputs of messages coming from other partners. Intuitively, this is possible because in the considered operational model messages coming from different partners are stored in distinct message queues. A difference between [ESOP09] and [GhilezanPPSY21] is that the former concentrates on deadlock freedom, while the latter considers also orphan message freedom. Notably, the subtyping in [GhilezanPPSY21] is proved to be precise (i.e. sound and complete), w.r.t. a notion of refinement that preserves orphan message freedom, deadlocks, and starvation, for a π𝜋\piitalic_π-calculus like language with multiparty sessions.

In [BCLYZ19, BravettiCLYZ21], we proposed a sound algorithm for the (unfair) asynchronous subtyping in [MariangiolaPreciness]. The sound algorithm that we present in this paper substantially differs from that of [BCLYZ19, BravettiCLYZ21]. Here we use witness trees that take under consideration both increasing and decreasing of accumulated input. In [BCLYZ19, BravettiCLYZ21], instead, only regular growing accumulation is considered. It is worth mentioning that in the context of multiparty session types there exist alternative sound (but not complete) algorithmic approaches. In particular, in [DagninoGD23] a multiparty approach is adopted: they study properties of networks of communicating end-point types instead of studying a subtyping relation on binary session types in isolation, as we do in this paper. A first phase of their algorithm infers global types from networks, and a second phase checks the well formedness of the inferred global types. Using techniques similar to ours (i.e. reduction from queue machines) well formedness is proved to be undecidable, but a sound algorithmic characterisation is proposed which is based on the notion of balancing. The authors of that paper show that, following their approach, one of the examples not captured by the algorithm in [BCLYZ19, BravettiCLYZ21] can be managed.

Finally, we mention work about refinement/subtyping in the context of asynchronous multiparty sessions, where the use of global types allows for the definition of decidable type systems. More precisely, both Castellani et al. [CastellaniDG21] and Li et al. [LiSW24] study a notion of refinement for (asynchronous) multiparty session types that ensures that the implementation of a given role can be replaced by another in the context of a specific global type. This means that the relation considers not only the component being refined, but also the other components of the system. Unlike most subtyping relation for asynchronous session types, this relation is decidable — this is notably due to the relation being restricted to the specific context of a given global type.

Future work

In future work, we will investigate the possibility to characterize a notion of fair asynchronous session subtyping which is complete with respect to our notion of fair refinement, in particular, we are interested in a less restrictive subtyping which includes also some form of output variance. We also plan to lift our study of fairness from binary to multiparty session types; in fact, the notions of fair compliance and refinement extend naturally to several partners. Finally, we will investigate a more refined termination condition for our algorithm using ideas from [BravettiCLYZ21, Theorem 3.8]. In particular, we plan to identify conditions similar to those in Definition 4 such that it is always guaranteed to find, during the computation of each branch of the simulation tree, a node with an ancestor satisfying such conditions. Then, the initial phase of the algorithm dedicated to the identification of the candidate subtrees can terminate when such nodes are detected, and the subsequent phase will continue to check whether such candidate subtrees are also witness subtrees.

Acknowledgments

We thank the anonymous reviewers for their valuable feedback and insightful suggestions, which have improved the quality of this work.

References

  • [Ada17] Adam Wiggins. The Twelve Factor methodology. https://12factor.net, 2017.
  • [BCL+19] Mario Bravetti, Marco Carbone, Julien Lange, Nobuko Yoshida, and Gianluigi Zavattaro. A sound algorithm for asynchronous session subtyping. In CONCUR, volume 140 of LIPIcs, pages 38:1–38:16. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2019.
  • [BCL+21] Mario Bravetti, Marco Carbone, Julien Lange, Nobuko Yoshida, and Gianluigi Zavattaro. A sound algorithm for asynchronous session subtyping and its implementation. Log. Methods Comput. Sci., 17(1), 2021. URL: https://lmcs.episciences.org/7238.
  • [BCZ17] Mario Bravetti, Marco Carbone, and Gianluigi Zavattaro. Undecidability of asynchronous session subtyping. Inf. Comput., 256:300–320, 2017.
  • [BCZ18] Mario Bravetti, Marco Carbone, and Gianluigi Zavattaro. On the boundary between decidability and undecidability of asynchronous session subtyping. Theor. Comput. Sci., 722:19–51, 2018.
  • [Bd10] Franco Barbanera and Ugo de’Liguoro. Two notions of sub-behaviour for session-based client/server systems. In PPDP’10, pages 155–164. ACM, 2010.
  • [BEJQ18] Ahmed Bouajjani, Constantin Enea, Kailiang Ji, and Shaz Qadeer. On the completeness of verifying message passing programs under bounded asynchrony. In CAV (2), volume 10982 of Lecture Notes in Computer Science, pages 372–391. Springer, 2018.
  • [BH16] Giovanni Tito Bernardi and Matthew Hennessy. Modelling session types using contracts. Mathematical Structures in Computer Science, 26(3):510–560, 2016.
  • [BLZ21] Mario Bravetti, Julien Lange, and Gianluigi Zavattaro. Fair refinement for asynchronous session types. In Stefan Kiefer and Christine Tasson, editors, Proc. FOSSACS 2021, volume 12650 of Lecture Notes in Computer Science, pages 144–163. Springer, 2021. doi:10.1007/978-3-030-71995-1\_8.
  • [BZ83] Daniel Brand and Pitro Zafiropulo. On communicating finite-state machines. J. ACM, 30(2):323–342, 1983.
  • [BZ08a] Mario Bravetti and Gianluigi Zavattaro. Contract Compliance and Choreography Conformance in the Presence of Message Queues. In WS-FM’08, volume 5387 of Lecture Notes in Computer Science, pages 37–54. Springer, 2008.
  • [BZ08b] Mario Bravetti and Gianluigi Zavattaro. A foundational theory of contracts for multi-party service composition. Fundam. Inform., 89(4):451–478, 2008. URL: http://content.iospress.com/articles/fundamenta-informaticae/fi89-4-05.
  • [BZ09] Mario Bravetti and Gianluigi Zavattaro. A theory of contracts for strong service compliance. Math. Struct. Comput. Sci., 19(3):601–638, 2009. doi:10.1017/S0960129509007658.
  • [BZ19] Mario Bravetti and Gianluigi Zavattaro. Relating session types and behavioural contracts: The asynchronous case. In SEFM, volume 11724 of Lecture Notes in Computer Science, pages 29–47. Springer, 2019.
  • [BZ21] Mario Bravetti and Gianluigi Zavattaro. Asynchronous session subtyping as communicating automata refinement. Softw. Syst. Model., 20(2):311–333, 2021. doi:10.1007/s10270-020-00838-x.
  • [CDCY14] Tzu-Chun Chen, Mariangiola Dezani-Ciancaglini, and Nobuko Yoshida. On the preciseness of subtyping in session types. In PPDP 2014, pages 146–135. ACM Press, 2014.
  • [CDG21] Ilaria Castellani, Mariangiola Dezani-Ciancaglini, and Paola Giannini. Global types and event structure semantics for asynchronous multiparty sessions. CoRR, abs/2102.00865, 2021. URL: https://arxiv.org/abs/2102.00865, arXiv:2102.00865.
  • [CDSY17] Tzu-Chun Chen, Mariangiola Dezani-Ciancaglini, Alceste Scalas, and Nobuko Yoshida. On the preciseness of subtyping in session types. Logical Methods in Computer Science, 13(2), 2017.
  • [CP22] Luca Ciccone and Luca Padovani. Fair termination of binary sessions. Proc. ACM Program. Lang., 6(POPL):1–30, 2022. doi:10.1145/3498666.
  • [DGD23] Francesco Dagnino, Paola Giannini, and Mariangiola Dezani-Ciancaglini. Deconfined global types for asynchronous sessions. Log. Methods Comput. Sci., 19(1), 2023. doi:10.46298/LMCS-19(1:3)2023.
  • [DY13] Pierre-Malo Deniélou and Nobuko Yoshida. Multiparty compatibility in communicating automata: Characterisation and synthesis of global session types. In Proc. ICALP 2013, volume 7966 of Lecture Notes in Computer Science, pages 174–186, 2013. doi:10.1007/978-3-642-39212-2\_18.
  • [GH05] Simon J. Gay and Malcolm Hole. Subtyping for session types in the pi calculus. Acta Inf., 42(2-3):191–225, 2005. doi:10.1007/s00236-005-0177-z.
  • [GKM06] Blaise Genest, Dietrich Kuske, and Anca Muscholl. A Kleene theorem and model checking algorithms for existentially bounded communicating automata. Inf. Comput., 204(6):920–956, 2006. doi:10.1016/j.ic.2006.01.005.
  • [GKM07] Blaise Genest, Dietrich Kuske, and Anca Muscholl. On communicating automata with bounded channels. Fundam. Inform., 80(1-3):147–167, 2007. URL: http://content.iospress.com/articles/fundamenta-informaticae/fi80-1-3-09.
  • [GPP+21] Silvia Ghilezan, Jovanka Pantovic, Ivan Prokic, Alceste Scalas, and Nobuko Yoshida. Precise subtyping for asynchronous multiparty sessions. Proc. ACM Program. Lang., 5(POPL):1–28, 2021. doi:10.1145/3434297.
  • [HYC16] Kohei Honda, Nobuko Yoshida, and Marco Carbone. Multiparty asynchronous session types. J. ACM, 63(1):9, 2016. doi:10.1145/2827695.
  • [Loh08] Niels Lohmann. Why does my service have no partners? In WS-FM, volume 5387 of Lecture Notes in Computer Science, pages 191–206. Springer, 2008.
  • [LSW24] Elaine Li, Felix Stutz, and Thomas Wies. Deciding subtyping for asynchronous multiparty sessions. In ESOP (1), volume 14576 of Lecture Notes in Computer Science, pages 176–205. Springer, 2024.
  • [LY17] Julien Lange and Nobuko Yoshida. On the undecidability of asynchronous session subtyping. In FOSSACS’17, volume 10203 of Lecture Notes in Computer Science, pages 441–457, 2017.
  • [LY19] Julien Lange and Nobuko Yoshida. Verifying asynchronous interactions via communicating session automata. In CAV (1), volume 11561 of Lecture Notes in Computer Science, pages 97–117. Springer, 2019.
  • [MY15] Dimitris Mostrous and Nobuko Yoshida. Session typing and asynchronous subtyping for the higher-order π𝜋\piitalic_π-calculus. Inf. Comput., 241:227–263, 2015. doi:10.1016/j.ic.2015.02.002.
  • [MYH09] Dimitris Mostrous, Nobuko Yoshida, and Kohei Honda. Global principal typing in partially commutative asynchronous sessions. In ESOP, volume 5502 of Lecture Notes in Computer Science, pages 316–332. Springer, 2009.
  • [NH84] Rocco De Nicola and Matthew Hennessy. Testing Equivalences for Processes. Theoretical Computer Science, 34:83–133, 1984.
  • [Pad13] Luca Padovani. Fair subtyping for open session types. In ICALP, volume 7966 of Lecture Notes in Computer Science, pages 373–384. Springer, 2013.
  • [Pad16] Luca Padovani. Fair subtyping for multi-party session types. Math. Struct. Comput. Sci., 26(3):424–464, 2016.
  • [RV07] Arend Rensink and Walter Vogler. Fair testing. Inf. Comput., 205(2):125–198, 2007. doi:10.1016/j.ic.2006.06.002.
  • [SD19] Paula Severi and Mariangiola Dezani-Ciancaglini. Observational equivalence for multiparty sessions. Fundam. Informaticae, 170(1-3):267–305, 2019. doi:10.3233/FI-2019-1863.
  • [The20] The Authors. Fair refinement for asynchronous session types. https://github.com/julien-lange/fair-asynchronous-subtyping, 2020.
  • [vGH19] Rob van Glabbeek and Peter Höfner. Progress, justness, and fairness. ACM Comput. Surv., 52(4):69:1–69:38, 2019.
  • [vGHH21] Rob van Glabbeek, Peter Höfner, and Ross Horne. Assuming just enough fairness to make session types complete for lock-freedom. In 36th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2021, Rome, Italy, June 29 - July 2, 2021, pages 1–13. IEEE, 2021. doi:10.1109/LICS52264.2021.9470531.
  • [Wei08] Daniela Weinberg. Efficient controllability analysis of open nets. In WS-FM, volume 5387 of Lecture Notes in Computer Science, pages 224–239. Springer, 2008.

Appendix A Proofs

A.1. Undecidability of Fair Refinement

Let T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] and S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ]; we have that TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S if and only if qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M. To prove this, we first characterize the set of types that are compliant with S𝑆Sitalic_S.

See 3

Proof A.1.

Let S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ].

We first prove the if part. Let Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT be a session type with input/output labels in Γ{E}Γ𝐸\Gamma\cup\{E\}roman_Γ ∪ { italic_E } s.t. SS¯similar-tosuperscript𝑆¯𝑆S^{\prime}\sim\overline{S}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∼ over¯ start_ARG italic_S end_ARG. We now prove that Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is compliant with S𝑆Sitalic_S. It is trivial to see that S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG is compliant with S𝑆Sitalic_S; this holds because in the configuration [S,ϵ]|[S¯,ϵ]conditional𝑆italic-ϵ¯𝑆italic-ϵ[S,\epsilon]|[\overline{S},\epsilon][ italic_S , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , italic_ϵ ] the two parties alternate inputs and outputs in such a way that their buffers have maximal length 1, and moreover the possibility to successfully terminate by selecting the ending label E𝐸Eitalic_E is never disallowed. By Corollary 2 we have that also all types SS¯similar-tosuperscript𝑆¯𝑆S^{\prime}\sim\overline{S}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∼ over¯ start_ARG italic_S end_ARG are compliant with S𝑆Sitalic_S.

We now move to the only-if part. Let Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT be a session type with input/output labels in Γ{E}Γ𝐸\Gamma\cup\{E\}roman_Γ ∪ { italic_E } s.t. Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is compliant with S𝑆Sitalic_S, i.e., [S,ϵ]|[S,ϵ]conditional𝑆italic-ϵsuperscript𝑆italic-ϵ[S,\epsilon]|[S^{\prime},\epsilon][ italic_S , italic_ϵ ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ϵ ] is a correct composition. We have that 𝗎𝗇𝖿𝗈𝗅𝖽(S)𝗎𝗇𝖿𝗈𝗅𝖽superscript𝑆\mathsf{unfold}(S^{\prime})sansserif_unfold ( italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) cannot start with an output selection; in fact, if, for instance, it starts with an output selection and it selects any label A𝐴Aitalic_A, the type S𝑆Sitalic_S can select a branch with a different label Asuperscript𝐴A^{\prime}italic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, thus blocking. The initial input branching of 𝗎𝗇𝖿𝗈𝗅𝖽(S)𝗎𝗇𝖿𝗈𝗅𝖽superscript𝑆\mathsf{unfold}(S^{\prime})sansserif_unfold ( italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) must have branchings labeled with all the symbols in ΓΓ\Gammaroman_Γ plus the ending symbol E𝐸Eitalic_E, in that these are the labels that can be initially selected by S𝑆Sitalic_S. In each continuation of Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, the unfolding of the type should start with an output selection, otherwise the entire system is blocked in that the continuation of S𝑆Sitalic_S after the initial output selection starts with an input branching. Moreover, given that these input branchings of the continuation of S𝑆Sitalic_S have only the initially selected label, the output selection in the continuation of Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT can have only such label. After each of these output selections of the continuation of Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, the same reasoning can be applied, excluding the case in which the label E𝐸Eitalic_E was initially selected. In this case, the continuation of Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT should be such that its unfolding is 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end. This because, the continuation of S𝑆Sitalic_S becomes 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end after executing the input branching labeled with E𝐸Eitalic_E. These constraints that we have just proved holding for the type Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT guarantee that SS¯similar-tosuperscript𝑆¯𝑆S^{\prime}\sim\overline{S}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∼ over¯ start_ARG italic_S end_ARG.

In order to prove the undecidability of refinement, we first show that T𝑇Titalic_T is compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG if and only if qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M.

See 4

Proof A.2.

Consider the queue machine M𝑀Mitalic_M, the types T=[[M,qf,E]]𝑇delimited-[]𝑀subscript𝑞𝑓𝐸T=[\![M,q_{f},E]\!]italic_T = [ [ italic_M , italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_E ] ] and S=[[M,E]]𝑆delimited-[]𝑀𝐸S=[\![M,E]\!]italic_S = [ [ italic_M , italic_E ] ] and the initial configuration [[[s]],ϵ]|[S¯,ϵ]conditionalsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆italic-ϵ[[\![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\epsilon][ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , italic_ϵ ]. The first transition is [T,ϵ]|[S¯,ϵ][[[s]],ϵ]|[S¯,$]superscriptabsentconditional𝑇italic-ϵ¯𝑆italic-ϵconditionalsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆currency-dollar[T,\epsilon]|[\overline{S},\epsilon]\stackrel{{\scriptstyle}}{{\rightarrow}}[[% \![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\$][ italic_T , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , italic_ϵ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , $ ].

We now define a partial mapping function {{}}\{\!\!\{{\,}\}\!\!\}{ { } } from configurations (reachable from the initial configuration [[[s]],ϵ]|[S¯,$]conditionalsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆currency-dollar[[\![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\$][ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , $ ]) to configurations in the queue machine computation:

  • {{[[[q]],ωT]|[S,ωS]}}=(q,ωTω(ωS)R)conditional-setsuperscriptdelimited-[]delimited-[]𝑞subscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆𝑞subscript𝜔𝑇𝜔superscriptsuperscriptsubscript𝜔𝑆𝑅\{\!\!\{{[[\![{q}]\!]^{\emptyset},\omega_{T}]|[S^{\prime},\omega_{S}^{\prime}]% }\}\!\!\}=(q,\omega_{T}\cdot\omega\cdot(\omega_{S}^{\prime})^{R}){ { [ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] } } = ( italic_q , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ⋅ italic_ω ⋅ ( italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) start_POSTSUPERSCRIPT italic_R end_POSTSUPERSCRIPT ) where

    • ω=ϵ𝜔italic-ϵ\omega=\epsilonitalic_ω = italic_ϵ if Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT starts with an input branching, or ω=A𝜔𝐴\omega=Aitalic_ω = italic_A if Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT starts with an output selection with unique label A𝐴Aitalic_A,

    • the operator \cdot stands for concatenation, and

    • and βRsuperscript𝛽𝑅\beta^{R}italic_β start_POSTSUPERSCRIPT italic_R end_POSTSUPERSCRIPT is the reverse of β𝛽\betaitalic_β.

Notice that {{[[[s]],ϵ]|[S¯,$]}}conditional-setsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆currency-dollar\{\!\!\{{[[\![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\$]}\}\!\!\}{ { [ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , $ ] } } is defined and it coincides with the initial configuration of the queue computation (s,$)𝑠currency-dollar(s,\$)( italic_s , $ ). In the following we use the following notation:

  • [[[q]],ωT]|[S,ωS][[[q]],ωT]|[S′′,ωS′′]conditionalsuperscriptdelimited-[]delimited-[]𝑞subscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆conditionalsuperscriptdelimited-[]delimited-[]superscript𝑞superscriptsubscript𝜔𝑇superscript𝑆′′superscriptsubscript𝜔𝑆′′[[\![{q}]\!]^{\emptyset},\omega_{T}]|[S^{\prime},\omega_{S}^{\prime}]% \Rightarrow[[\![{q^{\prime}}]\!]^{\emptyset},\omega_{T}^{\prime}]|[S^{\prime% \prime},\omega_{S}^{\prime\prime}][ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ⇒ [ [ [ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] if

    • [[[q]],ωT]|[S,ωS][[[q]],ωT]|[S′′,ωS′′]superscriptsuperscriptabsentconditionalsuperscriptdelimited-[]delimited-[]𝑞subscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆conditionalsuperscriptdelimited-[]delimited-[]superscript𝑞superscriptsubscript𝜔𝑇superscript𝑆′′superscriptsubscript𝜔𝑆′′[[\![{q}]\!]^{\emptyset},\omega_{T}]|[S^{\prime},\omega_{S}^{\prime}]\stackrel% {{\scriptstyle}}{{\rightarrow}}^{*}[[\![{q^{\prime}}]\!]^{\emptyset},\omega_{T% }^{\prime}]|[S^{\prime\prime},\omega_{S}^{\prime\prime}][ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ [ [ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] and

    • all intermediary traversed configurations are not in the domain of the partial mapping function {{}}\{\!\!\{{\,}\}\!\!\}{ { } }.

Given that, excluding the final state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT, for each state q𝑞qitalic_q of the queue machine [[q]]superscriptdelimited-[]delimited-[]𝑞[\![{q}]\!]^{\emptyset}[ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT reproduces the dequeue/enqueue actions of state q𝑞qitalic_q and S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG is a simple forwarder that repeatedly produces and consumes the same labels, we have that given qqf𝑞subscript𝑞𝑓q\neq q_{f}italic_q ≠ italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT we have (q,γ)M(q,γ)subscript𝑀𝑞𝛾superscript𝑞superscript𝛾(q,\gamma)\rightarrow_{M}(q^{\prime},\gamma^{\prime})( italic_q , italic_γ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) if and only if [[[q]],ωT]|[S,ωS][[[q]],ωT]|[S′′,ωS′′]conditionalsuperscriptdelimited-[]delimited-[]𝑞subscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆conditionalsuperscriptdelimited-[]delimited-[]superscript𝑞superscriptsubscript𝜔𝑇superscript𝑆′′superscriptsubscript𝜔𝑆′′[[\![{q}]\!]^{\emptyset},\omega_{T}]|[S^{\prime},\omega_{S}^{\prime}]% \Rightarrow[[\![{q^{\prime}}]\!]^{\emptyset},\omega_{T}^{\prime}]|[S^{\prime% \prime},\omega_{S}^{\prime\prime}][ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ⇒ [ [ [ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] with {{[[[q]],ωT]|[S,ωS]}}=(q,γ)conditional-setsuperscriptdelimited-[]delimited-[]𝑞subscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆𝑞𝛾\{\!\!\{{[[\![{q}]\!]^{\emptyset},\omega_{T}]|[S^{\prime},\omega_{S}^{\prime}]% }\}\!\!\}=(q,\gamma){ { [ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] } } = ( italic_q , italic_γ ) and {{[[[q]],ωT]|[S′′,ωS′′]}}=(q,γ)conditional-setsuperscriptdelimited-[]delimited-[]superscript𝑞superscriptsubscript𝜔𝑇superscript𝑆′′superscriptsubscript𝜔𝑆′′superscript𝑞superscript𝛾\{\!\!\{{[[\![{q^{\prime}}]\!]^{\emptyset},\omega_{T}^{\prime}]|[S^{\prime% \prime},\omega_{S}^{\prime\prime}]}\}\!\!\}=(q^{\prime},\gamma^{\prime}){ { [ [ [ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] } } = ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

We now prove the only-if part of the theorem. Assume that T𝑇Titalic_T is compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG. This means that there exists a computation leading to the final successful configuration. The unique occurrence of 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end is inside the type [[qf]]𝒮superscriptdelimited-[]delimited-[]subscript𝑞𝑓𝒮[\![{q_{f}}]\!]^{\mathcal{S}}[ [ italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ] ] start_POSTSUPERSCRIPT caligraphic_S end_POSTSUPERSCRIPT, hence we have [[[s]],ϵ]|[S¯,$][[[qf]],ωT]|[S,ωS]conditionalsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆currency-dollarconditionalsuperscriptdelimited-[]delimited-[]subscript𝑞𝑓subscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[[\![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\$]\Rightarrow\ldots% \Rightarrow[[\![{q_{f}}]\!]^{\emptyset},\omega_{T}]|[S^{\prime},\omega_{S}^{% \prime}][ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , $ ] ⇒ … ⇒ [ [ [ italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] thus implying that state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M.

We now prove the if part. Assume that qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M. Consider [[[s]],ϵ]|[S¯,$][T,ωT]|[S,ωS]superscriptsuperscriptabsentconditionalsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆currency-dollarconditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[[\![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\$]\stackrel{{\scriptstyle}}{% {\rightarrow}}^{*}[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{% \prime}][ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , $ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ]. There are two possible cases: either (i) it is possible to extend the sequence of transitions as follows [T,ωT]|[S,ωS][[[q]],ωT′′]|[S′′,ωS′′]superscriptsuperscriptabsentconditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆conditionalsuperscriptdelimited-[]delimited-[]𝑞superscriptsubscript𝜔𝑇′′superscript𝑆′′superscriptsubscript𝜔𝑆′′[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}]\stackrel{{% \scriptstyle}}{{\rightarrow}}^{*}[[\![{q}]\!]^{\emptyset},\omega_{T}^{\prime% \prime}]|[S^{\prime\prime},\omega_{S}^{\prime\prime}][ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ], for some state q𝑞qitalic_q, (ii) or during the sequence of transitions [[[s]],ϵ]|[S¯,$][T,ωT]|[S,ωS]superscriptsuperscriptabsentconditionalsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆currency-dollarconditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[[\![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\$]\stackrel{{\scriptstyle}}{% {\rightarrow}}^{*}[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{% \prime}][ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , $ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] a configuration is traversed in which the l.h.s. type is [[qf]]superscriptdelimited-[]delimited-[]subscript𝑞𝑓[\![{q_{f}}]\!]^{\emptyset}[ [ italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT.

In the first case (i), we have that (s,$)M{{[[[q]],ωT′′]|[S′′,ωS′′]}}superscriptsubscript𝑀𝑠currency-dollarconditional-setsuperscriptdelimited-[]delimited-[]𝑞superscriptsubscript𝜔𝑇′′superscript𝑆′′superscriptsubscript𝜔𝑆′′(s,\$)\rightarrow_{M}^{*}\{\!\!\{{[[\![{q}]\!]^{\emptyset},\omega_{T}^{\prime% \prime}]|[S^{\prime\prime},\omega_{S}^{\prime\prime}]}\}\!\!\}( italic_s , $ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT { { [ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] } }; moreover, in this computation of the queue machine the state qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is not traversed. This means that such a queue machine computation can be extended to reach qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT, hence the sequence of transitions [[[s]],ϵ]|[S¯,$][[[q]],ωT′′]|[S′′,ωS′′]superscriptsuperscriptabsentconditionalsuperscriptdelimited-[]delimited-[]𝑠italic-ϵ¯𝑆currency-dollarconditionalsuperscriptdelimited-[]delimited-[]𝑞superscriptsubscript𝜔𝑇′′superscript𝑆′′superscriptsubscript𝜔𝑆′′[[\![{s}]\!]^{\emptyset},\epsilon]|[\overline{S},\$]\stackrel{{\scriptstyle}}{% {\rightarrow}}^{*}[[\![{q}]\!]^{\emptyset},\omega_{T}^{\prime\prime}]|[S^{% \prime\prime},\omega_{S}^{\prime\prime}][ [ [ italic_s ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ϵ ] | [ over¯ start_ARG italic_S end_ARG , $ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ [ [ italic_q ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] can be additionally extended to reach a configuration where the l.h.s. type is [[qf]]superscriptdelimited-[]delimited-[]subscript𝑞𝑓[\![{q_{f}}]\!]^{\emptyset}[ [ italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT. From such a configuration, we have that there are only finitely many transitions leading to the final successful configuration (in this final transitions both the queues are emptied and both types become 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end).

In the second case (ii), we have that a configuration whose l.h.s. type is [[qf]]superscriptdelimited-[]delimited-[]subscript𝑞𝑓[\![{q_{f}}]\!]^{\emptyset}[ [ italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ] ] start_POSTSUPERSCRIPT ∅ end_POSTSUPERSCRIPT. As just observed, this means that the configuration [T,ωT]|[S,ωS]conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}][ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] is an intermediary configuration in the final sequence of transitions leading to the final successful configuration (in which both the queues are emptied and both types are 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end).

By combining Theorem 4 with Lemma 3, we can finally prove that our encoding of queue machines into session types correctly reduces state reachability into refinement.

See 5

Proof A.3.

We first prove the only-if part. Let TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S. By Lemma 3 we have that S𝑆Sitalic_S is compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG. Given that TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S, also T𝑇Titalic_T is compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG. By Theorem 4 this implies that qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M.

We now prove the if part. Assume that qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in M𝑀Mitalic_M. As discussed in Section 2 (see footnote 2) our encoding of queue machines assumes that the set \mathcal{L}caligraphic_L of labels in the Definition 2.1 of session types includes the symbols in the queue machine alphabet ΓΓ\Gammaroman_Γ plus the symbol E𝐸Eitalic_E. We now consider a queue machine M=(Q,Σ,ΓΓ,$,s,δδ)M^{\prime}=(Q^{\prime},\Sigma,\Gamma^{\prime}\supseteq\Gamma,\$,s,\delta^{% \prime}\supseteq\delta)italic_M start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = ( italic_Q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , roman_Σ , roman_Γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊇ roman_Γ , $ , italic_s , italic_δ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊇ italic_δ ) obtained by replacing the queue alphabet ΓΓ\Gammaroman_Γ with a richer alphabet ΓsuperscriptΓ\Gamma^{\prime}roman_Γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that =Γ{E}superscriptΓ𝐸\mathcal{L}=\Gamma^{\prime}\cup\{E\}caligraphic_L = roman_Γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∪ { italic_E }, and by extending δ𝛿\deltaitalic_δ with a new transition relation δsuperscript𝛿\delta^{\prime}italic_δ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT which includes also the additional queue symbols in its domain. The behaviour of δsuperscript𝛿\delta^{\prime}italic_δ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT on these additional symbols is irrelevant because these symbols will never be placed in the queue, given that the input alphabet is still ΣΣ\Sigmaroman_Σ. We have that qfsubscript𝑞𝑓q_{f}italic_q start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT is reachable in Msuperscript𝑀M^{\prime}italic_M start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, simply because Msuperscript𝑀M^{\prime}italic_M start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT reproduces the same computations of M𝑀Mitalic_M. By Theorem 4 we have that T𝑇Titalic_T is compliant with S¯¯𝑆\overline{S}over¯ start_ARG italic_S end_ARG. By Corollary 2 we have that T𝑇Titalic_T is compliant with all Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that SS¯similar-tosuperscript𝑆¯𝑆S^{\prime}\sim\overline{S}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∼ over¯ start_ARG italic_S end_ARG. Under the assumption that =Γ{E}superscriptΓ𝐸\mathcal{L}=\Gamma^{\prime}\cup\{E\}caligraphic_L = roman_Γ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∪ { italic_E }, by Lemma 3 we have that the set of types Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that SS¯similar-tosuperscript𝑆¯𝑆S^{\prime}\sim\overline{S}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∼ over¯ start_ARG italic_S end_ARG precisely corresponds with the types with which S𝑆Sitalic_S is compliant. We have observed that T𝑇Titalic_T is compliant with all such Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, hence we can conclude that TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S.

A.2. Controllability Characterisation

In this section we will prove the following theorem about controllability characterisation.

See 7

We start by introducing some notions and definitions that will be needed in the proof.

First of all we present an equivalent definition, based on purely structural induction, of the 𝗈𝗄𝗈𝗄\,\mathsf{ok}sansserif_ok predicate introduced in Definition 2 characterizing session type controllability. {defi} Given a session type T𝑇Titalic_T, we define the judgment T𝗈𝗄𝑇𝗈𝗄T\,\mathsf{ok}italic_T sansserif_ok inductively as follows: {mathpar} \inferruletok

\inferrule

endok

\inferrule

end​∈​ T ∨∃t’ ​:​ t’ ​≠​ tt’ ​∈​ free(T) T  ok μt.T  ok
\inferrule T ok &{l:T}  ok

\inferrule

∀i ∈I . T_i  ok ⊕{l_i:T_i}_i∈I  ok where 𝖿𝗋𝖾𝖾(T)𝖿𝗋𝖾𝖾𝑇\mathsf{free}(T)sansserif_free ( italic_T ) is the set of variables t𝑡titalic_t occurring free in T𝑇Titalic_T.

In the following we will use a reformulation of session types in terms of equation sets. In equation set notations we will use terms T𝑇Titalic_T that have the same syntax as those used to denote session types, excluding the μ𝐭._formulae-sequence𝜇𝐭_\mu\mathbf{t}.\_italic_μ bold_t . _ recursion operator. Notice that in such notations we consider possibly open terms T𝑇Titalic_T (i.e. such that 𝖿𝗋𝖾𝖾(T)𝖿𝗋𝖾𝖾𝑇\mathsf{free}(T)sansserif_free ( italic_T ) is not empty). Session types are, thus, denoted by T{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝑇conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌T\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\}italic_T { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars }, with 𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌\mathsf{Vars}sansserif_Vars being a set of variables 𝐭𝐭\mathbf{t}bold_t that includes all variables in 𝖿𝗋𝖾𝖾(T)𝖿𝗋𝖾𝖾𝑇\mathsf{free}(T)sansserif_free ( italic_T ) and also in 𝖿𝗋𝖾𝖾(T𝐭)𝖿𝗋𝖾𝖾subscript𝑇𝐭\mathsf{free}(T_{\mathbf{t}})sansserif_free ( italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ) for all 𝐭𝖵𝖺𝗋𝗌𝐭𝖵𝖺𝗋𝗌\mathbf{t}\in\mathsf{Vars}bold_t ∈ sansserif_Vars.

Formally, given a session type T𝑇Titalic_T (we assume with loss of generality that each of its recursions uses a variable with a different name) we consider its equivalent equation set notation 𝖾𝗌𝗇(T)=T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝖾𝗌𝗇𝑇subscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌\mathsf{esn}(T)=T_{\mathsf{init}}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in% \mathsf{Vars}\}sansserif_esn ( italic_T ) = italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars }, defined as follows:

  • 𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌\mathsf{Vars}sansserif_Vars is the set of variable names used in the recursions of T𝑇Titalic_T

  • T𝗂𝗇𝗂𝗍subscript𝑇𝗂𝗇𝗂𝗍T_{\mathsf{init}}italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT is the only term without recursion operators satisfying: there exists a set of terms T𝐭subscriptsuperscript𝑇𝐭T^{\prime}_{\mathbf{t}}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT, one for each variable 𝐭𝖿𝗋𝖾𝖾(T𝗂𝗇𝗂𝗍)𝐭𝖿𝗋𝖾𝖾subscript𝑇𝗂𝗇𝗂𝗍\mathbf{t}\in\mathsf{free}(T_{\mathsf{init}})bold_t ∈ sansserif_free ( italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT ), such that T𝗂𝗇𝗂𝗍{T𝐭/𝐭𝐭𝖿𝗋𝖾𝖾(T𝗂𝗇𝗂𝗍)}=Tsubscript𝑇𝗂𝗇𝗂𝗍conditional-setsubscriptsuperscript𝑇𝐭𝐭𝐭𝖿𝗋𝖾𝖾subscript𝑇𝗂𝗇𝗂𝗍𝑇T_{\mathsf{init}}\{T^{\prime}_{\mathbf{t}}/\mathbf{t}\mid\mathbf{t}\in\mathsf{% free}(T_{\mathsf{init}})\}=Titalic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT / bold_t ∣ bold_t ∈ sansserif_free ( italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT ) } = italic_T

  • each T𝐭subscript𝑇𝐭T_{\mathbf{t}}italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT, with 𝐭𝖵𝖺𝗋𝗌𝐭𝖵𝖺𝗋𝗌\mathbf{t}\in\mathsf{Vars}bold_t ∈ sansserif_Vars, is the only term without recursion operators satisfying: there exists a set of variables 𝖵𝖺𝗋𝗌𝐭𝖿𝗋𝖾𝖾(T𝐭)subscript𝖵𝖺𝗋𝗌𝐭𝖿𝗋𝖾𝖾subscript𝑇𝐭\mathsf{Vars}_{\mathbf{t}}\subseteq\mathsf{free}(T_{\mathbf{t}})sansserif_Vars start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ⊆ sansserif_free ( italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ) and a set of terms T𝐭subscriptsuperscript𝑇superscript𝐭T^{\prime}_{\mathbf{t}^{\prime}}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT, one for each variable 𝐭𝖵𝖺𝗋𝗌𝐭superscript𝐭subscript𝖵𝖺𝗋𝗌𝐭\mathbf{t}^{\prime}\in\mathsf{Vars}_{\mathbf{t}}bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ sansserif_Vars start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT, such that T𝐭{T𝐭/𝐭𝐭𝖵𝖺𝗋𝗌𝐭}=T′′subscript𝑇𝐭conditional-setsubscript𝑇superscript𝐭superscript𝐭superscript𝐭subscript𝖵𝖺𝗋𝗌𝐭superscript𝑇′′T_{\mathbf{t}}\{T_{\mathbf{t}^{\prime}}/\mathbf{t}^{\prime}\mid\mathbf{t}^{% \prime}\in\mathsf{Vars}_{\mathbf{t}}\}=T^{\prime\prime}italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT { italic_T start_POSTSUBSCRIPT bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT / bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∣ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ sansserif_Vars start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT } = italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT with μ𝐭.T′′formulae-sequence𝜇𝐭superscript𝑇′′\mu\mathbf{t}.T^{\prime\prime}italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT occurring in T𝑇Titalic_T.

{defi}

[Unfolding]Given session type in equation set notation we define its unfolding 𝗎𝗇𝖿𝗈𝗅𝖽(T{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌})𝗎𝗇𝖿𝗈𝗅𝖽𝑇conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌\mathsf{unfold}(T\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\})sansserif_unfold ( italic_T { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } ) as follows:

𝗎𝗇𝖿𝗈𝗅𝖽(T{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌})={𝗎𝗇𝖿𝗈𝗅𝖽(T𝐭{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌})if T=𝐭T{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}otherwise𝗎𝗇𝖿𝗈𝗅𝖽𝑇conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌cases𝗎𝗇𝖿𝗈𝗅𝖽subscript𝑇superscript𝐭conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌if T=𝐭𝑇conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌otherwise\mathsf{unfold}(T\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\})=% \begin{cases}\mathsf{unfold}(T_{\mathbf{t}^{\prime}}\{\mathbf{t}=T_{\mathbf{t}% }\mid\mathbf{t}\in\mathsf{Vars}\})&\text{if $T=\mathbf{t}^{\prime}$}\\ T\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\}&\text{otherwise}% \end{cases}sansserif_unfold ( italic_T { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } ) = { start_ROW start_CELL sansserif_unfold ( italic_T start_POSTSUBSCRIPT bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } ) end_CELL start_CELL if italic_T = bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_CELL end_ROW start_ROW start_CELL italic_T { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } end_CELL start_CELL otherwise end_CELL end_ROW

Notice that unfolding is well defined because we consider session types with guarded recursion in equation set notation.

The transition relation for configurations [T1{𝐭=T1,𝐭𝐭𝖵𝖺𝗋𝗌1},ω1]|[T2{𝐭=T2,𝐭𝐭𝖵𝖺𝗋𝗌2},ω2]conditionalsubscript𝑇1conditional-set𝐭subscript𝑇1𝐭𝐭subscript𝖵𝖺𝗋𝗌1subscript𝜔1subscript𝑇2conditional-set𝐭subscript𝑇2𝐭𝐭subscript𝖵𝖺𝗋𝗌2subscript𝜔2[T_{1}\{\mathbf{t}=T_{1,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}_{1}\},\omega% _{1}]|[T_{2}\{\mathbf{t}=T_{2,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}_{2}\},% \omega_{2}][ italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 1 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 2 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ], with Ti{𝐭=Ti,𝐭𝐭𝖵𝖺𝗋𝗌i}subscript𝑇𝑖conditional-set𝐭subscript𝑇𝑖𝐭𝐭subscript𝖵𝖺𝗋𝗌𝑖T_{i}\{\mathbf{t}=T_{i,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}_{i}\}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT italic_i , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT }, for i{1,2}𝑖12i\in\{1,2\}italic_i ∈ { 1 , 2 }, being session types in equation set notation, is defined as in Definition 2.2 by using the above definition of unfolding (and by assuming that the {𝐭=Ti,𝐭𝐭𝖵𝖺𝗋𝗌i}conditional-set𝐭subscript𝑇𝑖𝐭𝐭subscript𝖵𝖺𝗋𝗌𝑖\{\mathbf{t}=T_{i,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}_{i}\}{ bold_t = italic_T start_POSTSUBSCRIPT italic_i , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } equational part is copied, for both T1subscript𝑇1T_{1}italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and T2subscript𝑇2T_{2}italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT, after every transition).

Given T1subscript𝑇1T_{1}italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and T2subscript𝑇2T_{2}italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT session types, it obviously holds (by standard arguments) that the transition system of [T,ϵ]|[S,ϵ]conditional𝑇italic-ϵ𝑆italic-ϵ[T,\epsilon]|[S,\epsilon][ italic_T , italic_ϵ ] | [ italic_S , italic_ϵ ] is bisimilar to that of [𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵ[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon][ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ], hence that: T𝑇Titalic_T and S𝑆Sitalic_S are compliant if and only if 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) and 𝖾𝗌𝗇(S)𝖾𝗌𝗇𝑆\mathsf{esn}(S)sansserif_esn ( italic_S ) are compliant.

We now define predicate 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl for session types in equation set notation. 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl is defined as in Definition 2, by assuming that predicate 𝗈𝗄𝗈𝗄\,\mathsf{ok}sansserif_ok is, instead, defined as follows. T{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝗈𝗄𝑇conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌𝗈𝗄T\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\}\,\mathsf{ok}italic_T { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } sansserif_ok if there exists an indexing (total order) 𝐭isubscript𝐭𝑖{\mathbf{t}}_{i}bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT on the variables of 𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌\mathsf{Vars}sansserif_Vars such that {𝐭i1in}=𝖵𝖺𝗋𝗌conditional-setsubscript𝐭𝑖1𝑖𝑛𝖵𝖺𝗋𝗌\{\mathbf{t}_{i}\mid 1\leq i\leq n\}=\mathsf{Vars}{ bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∣ 1 ≤ italic_i ≤ italic_n } = sansserif_Vars and, for all i𝑖iitalic_i, with 1in1𝑖𝑛1\leq i\leq n1 ≤ italic_i ≤ italic_n, it, holds:

𝐞𝐧𝐝Ti𝐭j:j<i𝐭j𝖿𝗋𝖾𝖾(Ti):𝐞𝐧𝐝subscript𝑇𝑖subscript𝐭𝑗𝑗𝑖subscript𝐭𝑗𝖿𝗋𝖾𝖾subscript𝑇𝑖\mathbf{end}\!\in\!T_{i}\vee\exists\mathbf{t}_{j}\!:\!j<i\wedge\mathbf{t}_{j}% \!\in\!\mathsf{free}(T_{i})bold_end ∈ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∨ ∃ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_j < italic_i ∧ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT )

Moreover, as in Definition 2, in order to establish 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl of a session type T{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝑇conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌T\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\}italic_T { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } input prefix replacement must preliminarily be performed, so to obtain session types T{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}superscript𝑇conditional-set𝐭subscriptsuperscript𝑇𝐭𝐭superscript𝖵𝖺𝗋𝗌T^{\prime}\{\mathbf{t}=T^{\prime}_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}^{% \prime}\}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT { bold_t = italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } where 𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌\mathsf{Vars}^{\prime}\subseteq\mathsf{Vars}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊆ sansserif_Vars and in both term T𝗌𝗂𝗇(T)superscript𝑇𝗌𝗂𝗇𝑇T^{\prime}\in\mathsf{sin}(T)italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ sansserif_sin ( italic_T ) and all terms T𝐭𝗌𝗂𝗇(T𝐭)subscriptsuperscript𝑇𝐭𝗌𝗂𝗇subscript𝑇𝐭T^{\prime}_{\mathbf{t}}\in\mathsf{sin}(T_{\mathbf{t}})italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∈ sansserif_sin ( italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ), with 𝐭𝖵𝖺𝗋𝗌𝐭superscript𝖵𝖺𝗋𝗌\mathbf{t}\in\mathsf{Vars}^{\prime}bold_t ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, all input prefixes have a single label.

Proposition 16.

T𝑇Titalic_T 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl if and only if 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl.

Proof A.4.

We first show that T𝑇Titalic_T 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl implies 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl. Given Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT obtained by input prefix replacement from T𝑇Titalic_T (so to have input prefixes with single choices) that satisfies the 𝗈𝗄𝗈𝗄\,\mathsf{ok}sansserif_ok predicate, we correspondingly consider 𝖾𝗌𝗇(T)𝖾𝗌𝗇superscript𝑇\mathsf{esn}(T^{\prime})sansserif_esn ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ), which is an input prefix replacement of 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ). 𝖾𝗌𝗇(T)𝗈𝗄𝖾𝗌𝗇superscript𝑇𝗈𝗄\mathsf{esn}(T^{\prime})\,\mathsf{ok}sansserif_esn ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) sansserif_ok is an immediate consequence of T𝗈𝗄superscript𝑇𝗈𝗄T^{\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT sansserif_ok by considering the indexing 𝐭isubscript𝐭𝑖{\mathbf{t}}_{i}bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT of variable names used in the recursions of T𝑇Titalic_T obtained as follows. We incrementally assign indexes to variables (starting from 1111) according to a depth-first visit of the syntax tree of T𝑇Titalic_T as follows. When we are at a μ𝐭.T′′formulae-sequence𝜇𝐭superscript𝑇′′\mu\mathbf{t}.T^{\prime\prime}italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT node, we have two cases. Either 𝐭𝐭\mathbf{t}bold_t has already an assigned index (not possibile at the beginning) or not. In the latter case: we consider all μ𝐭._formulae-sequence𝜇superscript𝐭_\mu\mathbf{t}^{\prime}.\_italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . _ operators occurring in T′′superscript𝑇′′T^{\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, if any, that syntactically include 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end or variable 𝐭′′superscript𝐭′′\mathbf{t}^{\prime\prime}bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that 𝐭′′𝐭𝐭′′𝖿𝗋𝖾𝖾(T′′)superscript𝐭′′𝐭superscript𝐭′′𝖿𝗋𝖾𝖾superscript𝑇′′\mathbf{t}^{\prime\prime}\!\neq\!\mathbf{t}\wedge\mathbf{t}^{\prime\prime}\!% \in\!\mathsf{free}(T^{\prime\prime})bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ≠ bold_t ∧ bold_t start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ∈ sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) and we assign an index to all such 𝐭superscript𝐭\mathbf{t}^{\prime}bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT (incrementing the last assigned index) in increasing order from the innermost to the outermost; then we assign an index to 𝐭𝐭\mathbf{t}bold_t (incrementing the last assigned index). Finally, in both cases, we visit all the μ𝐭._formulae-sequence𝜇superscript𝐭_\mu\mathbf{t}^{\prime}.\_italic_μ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT . _ descendants (with no other recursion node in-between) of the μ𝐭._formulae-sequence𝜇𝐭_\mu\mathbf{t}.\_italic_μ bold_t . _ node, if any.

We now show that 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl implies T𝑇Titalic_T 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl. Given T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}subscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌T_{\mathsf{init}}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\}italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } obtained by input prefix replacement from 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) that satisfies the 𝗈𝗄𝗈𝗄\,\mathsf{ok}sansserif_ok predicate, we correspondingly consider the only term Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT which is an input prefix replacement of T𝑇Titalic_T such that 𝖾𝗌𝗇(T)=T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝖾𝗌𝗇superscript𝑇subscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌\mathsf{esn}(T^{\prime})=T_{\mathsf{init}}\{\mathbf{t}=T_{\mathbf{t}}\mid% \mathbf{t}\in\mathsf{Vars}\}sansserif_esn ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars }. We show that T𝗈𝗄superscript𝑇𝗈𝗄T^{\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT sansserif_ok (Definition A.2 above) by structural induction:

  • For the base cases 𝐭𝗈𝗄𝐭𝗈𝗄{\mathbf{t}\,\mathsf{ok}}bold_t sansserif_ok and 𝐞𝐧𝐝𝗈𝗄𝐞𝐧𝐝𝗈𝗄{\mathbf{end}\,\mathsf{ok}}bold_end sansserif_ok we have nothing to show.

  • &{l:T′′}𝗈𝗄conditional-set𝑙superscript𝑇′′𝗈𝗄\&\{{l}:{T^{\prime\prime}}\}\,\mathsf{ok}& { italic_l : italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT } sansserif_ok and {li:T′′i}iI𝗈𝗄direct-sumsubscriptconditional-setsubscript𝑙𝑖subscriptsuperscript𝑇′′𝑖𝑖𝐼𝗈𝗄\oplus\{{l}_{i}:{T^{\prime\prime}}_{i}\}_{i\in I}\,\mathsf{ok}⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT sansserif_ok are a direct consequence of the induction hypothesis, i.e. T′′𝗈𝗄superscript𝑇′′𝗈𝗄T^{\prime\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT sansserif_ok and iI.Ti′′𝗈𝗄formulae-sequencefor-all𝑖𝐼subscriptsuperscript𝑇′′𝑖𝗈𝗄\forall i\in I.\ T^{\prime\prime}_{i}\,\mathsf{ok}∀ italic_i ∈ italic_I . italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT sansserif_ok, respectively.

  • μ𝐭.T′′𝗈𝗄formulae-sequence𝜇𝐭superscript𝑇′′𝗈𝗄\mu\mathbf{t}.T^{\prime\prime}\,\mathsf{ok}italic_μ bold_t . italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT sansserif_ok is a direct consequence of the induction hypothesis T′′𝗈𝗄superscript𝑇′′𝗈𝗄T^{\prime\prime}\,\mathsf{ok}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT sansserif_ok and of the fact that: 𝐞𝐧𝐝T′′𝐭:𝐭𝐭𝐭𝖿𝗋𝖾𝖾(T′′):𝐞𝐧𝐝superscript𝑇′′superscript𝐭superscript𝐭𝐭superscript𝐭𝖿𝗋𝖾𝖾superscript𝑇′′\mathbf{end}\!\in\!T^{\prime\prime}\vee\exists\mathbf{t}^{\prime}\!:\!\mathbf{% t}^{\prime}\!\neq\!\mathbf{t}\wedge\mathbf{t}^{\prime}\!\in\!\mathsf{free}(T^{% \prime\prime})bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ∨ ∃ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT : bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≠ bold_t ∧ bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ). The latter is shown as follows. From T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝗈𝗄subscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌𝗈𝗄T_{\mathsf{init}}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\}\,% \mathsf{ok}italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } sansserif_ok we know that there exists a variable indexing 𝐭isubscript𝐭𝑖{\mathbf{t}}_{i}bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT such that, for all iI𝑖𝐼i\in Iitalic_i ∈ italic_I it, holds: 𝐞𝐧𝐝Ti𝐭j:j<i𝐭j𝖿𝗋𝖾𝖾(Ti):𝐞𝐧𝐝subscript𝑇𝑖subscript𝐭𝑗𝑗𝑖subscript𝐭𝑗𝖿𝗋𝖾𝖾subscript𝑇𝑖\mathbf{end}\!\in\!T_{i}\vee\exists\mathbf{t}_{j}\!:\!j<i\wedge\mathbf{t}_{j}% \!\in\!\mathsf{free}(T_{i})bold_end ∈ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∨ ∃ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_j < italic_i ∧ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ). So, given index i𝑖iitalic_i such that 𝐭i=𝐭subscript𝐭𝑖𝐭\mathbf{t}_{i}=\mathbf{t}bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT = bold_t, we have to show: 𝐞𝐧𝐝T′′z:zi𝐭z𝖿𝗋𝖾𝖾(T′′):𝐞𝐧𝐝superscript𝑇′′𝑧𝑧𝑖subscript𝐭𝑧𝖿𝗋𝖾𝖾superscript𝑇′′\mathbf{end}\!\in\!T^{\prime\prime}\vee\exists z\!:\!z\!\neq\!i\wedge\mathbf{% \mathbf{t}}_{z}\!\in\!\mathsf{free}(T^{\prime\prime})bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ∨ ∃ italic_z : italic_z ≠ italic_i ∧ bold_t start_POSTSUBSCRIPT italic_z end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ). What we know is that 𝐞𝐧𝐝Ti𝐭j:j<i𝐭j𝖿𝗋𝖾𝖾(Ti):𝐞𝐧𝐝subscript𝑇𝑖subscript𝐭𝑗𝑗𝑖subscript𝐭𝑗𝖿𝗋𝖾𝖾subscript𝑇𝑖\mathbf{end}\!\in\!T_{i}\vee\exists\mathbf{t}_{j}\!:\!j<i\wedge\mathbf{t}_{j}% \!\in\!\mathsf{free}(T_{i})bold_end ∈ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∨ ∃ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_j < italic_i ∧ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ), so there are two cases:

    1. (1)

      Either it holds 𝐞𝐧𝐝T′′𝐭j𝖿𝗋𝖾𝖾(T′′)𝐞𝐧𝐝superscript𝑇′′subscript𝐭𝑗𝖿𝗋𝖾𝖾superscript𝑇′′\mathbf{end}\!\in\!T^{\prime\prime}\vee\mathbf{t}_{j}\!\in\!\mathsf{free}(T^{% \prime\prime})bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ∨ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) and we are done (with z=j𝑧𝑗z=jitalic_z = italic_j).

    2. (2)

      Or μ𝐭j.T′′′formulae-sequence𝜇subscript𝐭𝑗superscript𝑇′′′\mu\mathbf{t}_{j}.T^{\prime\prime\prime}italic_μ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT . italic_T start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT, for some T′′′superscript𝑇′′′T^{\prime\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT, is a subterm of T′′superscript𝑇′′T^{\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT. In this case we show that: 𝐞𝐧𝐝T′′′z:zi𝐭z𝖿𝗋𝖾𝖾(T′′′):𝐞𝐧𝐝superscript𝑇′′′𝑧𝑧𝑖subscript𝐭𝑧𝖿𝗋𝖾𝖾superscript𝑇′′′\mathbf{end}\!\in\!T^{\prime\prime\prime}\vee\exists z\!:\!z\!\neq\!i\wedge% \mathbf{\mathbf{t}}_{z}\!\in\!\mathsf{free}(T^{\prime\prime\prime})bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ∨ ∃ italic_z : italic_z ≠ italic_i ∧ bold_t start_POSTSUBSCRIPT italic_z end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ). To do this we consider index j𝑗jitalic_j and the defining term Tjsubscript𝑇𝑗T_{j}italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT in its equation: we know that 𝐞𝐧𝐝Tj𝐭k:k<j𝐭k𝖿𝗋𝖾𝖾(Tj):𝐞𝐧𝐝subscript𝑇𝑗subscript𝐭𝑘𝑘𝑗subscript𝐭𝑘𝖿𝗋𝖾𝖾subscript𝑇𝑗\mathbf{end}\!\in\!T_{j}\vee\exists\mathbf{t}_{k}\!:\!k<j\wedge\mathbf{t}_{k}% \!\in\!\mathsf{free}(T_{j})bold_end ∈ italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ∨ ∃ bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT : italic_k < italic_j ∧ bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ). Now again we have the same two cases, considering index k𝑘kitalic_k instead of j𝑗jitalic_j and term T′′′superscript𝑇′′′T^{\prime\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT instead of term T′′superscript𝑇′′T^{\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT. Notice that we cannot proceed like this forever because the syntax of T′′superscript𝑇′′T^{\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is finite, hence case 1.11.1 . must eventually apply. Moreover when this happens, we are sure that the variable 𝐭zsubscript𝐭𝑧\mathbf{t}_{z}bold_t start_POSTSUBSCRIPT italic_z end_POSTSUBSCRIPT that we detect is different from 𝐭=𝐭i𝐭subscript𝐭𝑖\mathbf{t}=\mathbf{t}_{i}bold_t = bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT (i.e. zi𝑧𝑖z\neq iitalic_z ≠ italic_i) because the indexing of the variables that we consider are always strictly smaller than i𝑖iitalic_i.

We are now in a position to prove the desired theorem. We prove implications in the two opposite directions one at a time.

Theorem 17.

If there exists a session type S𝑆Sitalic_S such that T𝑇Titalic_T and S𝑆Sitalic_S are compliant then T𝑇Titalic_T 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl.

Proof A.5.

Since T𝑇Titalic_T and S𝑆Sitalic_S are compliant, as observed above, we have also that 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) and 𝖾𝗌𝗇(S)𝖾𝗌𝗇𝑆\mathsf{esn}(S)sansserif_esn ( italic_S ) are compliant. Therefore (the transition system of) configuration [𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵ[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon][ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ] is a correct composition according to Definition 2.2.

We now show that 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl: by Proposition 16 this implies that T𝑇Titalic_T 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl. In order to do this we need to enrich the transition system representation of the behaviour of configurations [T1{𝐭=T1,𝐭𝐭𝖵𝖺𝗋𝗌𝟣},ω1]|[T2{𝐭=T2,𝐭𝐭𝖵𝖺𝗋𝗌𝟤},ω2]conditionalsubscript𝑇1conditional-set𝐭subscript𝑇1𝐭𝐭subscript𝖵𝖺𝗋𝗌1subscript𝜔1subscript𝑇2conditional-set𝐭subscript𝑇2𝐭𝐭subscript𝖵𝖺𝗋𝗌2subscript𝜔2[T_{1}\{\mathbf{t}=T_{1,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars_{1}}\},\omega% _{1}]|[T_{2}\{\mathbf{t}=T_{2,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars_{2}}\},% \omega_{2}][ italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 1 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT sansserif_1 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 2 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT sansserif_2 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ]. We assume the transition relation \rightarrow defined in Definition 2.2 to be enriched as follows: \rightarrow transitions originated from outputs of T1subscript𝑇1T_{1}italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT (rule 1.11.1 . of Definition 2.2) are assumed to be decorated with the label ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT of the performed output (denoted by lj¯superscript¯subscript𝑙𝑗\,\mathop{\longrightarrow}\limits^{\overline{l_{j}}}\,⟶ start_POSTSUPERSCRIPT over¯ start_ARG italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT end_ARG end_POSTSUPERSCRIPT), while \rightarrow transitions originated from inputs of T1subscript𝑇1T_{1}italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT (rule 2.22.2 . of Definition 2.2) are assumed to be decorated with the label ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT of the performed input (denoted by ljsuperscriptsubscript𝑙𝑗\,\mathop{\longrightarrow}\limits^{l_{j}}\,⟶ start_POSTSUPERSCRIPT italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT end_POSTSUPERSCRIPT). Notice that, in case of transitions originated from inputs or outputs of T2subscript𝑇2T_{2}italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT no decoration is added to transitions \rightarrow. Moreover, rule 3.33.3 . (about recursion unfolding) of Definition 2.2 is assumed to just copy the decoration labeling the transition (if there is any).

We now consider such an enriched transition system over configurations [T1{𝐭=T1,𝐭𝐭𝖵𝖺𝗋𝗌𝟣},ω1]|[T2{𝐭=T2,𝐭𝐭𝖵𝖺𝗋𝗌𝟤},ω2]conditionalsubscript𝑇1conditional-set𝐭subscript𝑇1𝐭𝐭subscript𝖵𝖺𝗋𝗌1subscript𝜔1subscript𝑇2conditional-set𝐭subscript𝑇2𝐭𝐭subscript𝖵𝖺𝗋𝗌2subscript𝜔2[T_{1}\{\mathbf{t}=T_{1,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars_{1}}\},\omega% _{1}]|[T_{2}\{\mathbf{t}=T_{2,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars_{2}}\},% \omega_{2}][ italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 1 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT sansserif_1 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 2 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT sansserif_2 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ]. We use s𝑠sitalic_s to range over these configurations. We say that a configuration s=[T1{𝐭=T1,𝐭𝐭𝖵𝖺𝗋𝗌𝟣},ω1]|[T2{𝐭=T2,𝐭𝐭𝖵𝖺𝗋𝗌𝟤},ω2]𝑠conditionalsubscript𝑇1conditional-set𝐭subscript𝑇1𝐭𝐭subscript𝖵𝖺𝗋𝗌1subscript𝜔1subscript𝑇2conditional-set𝐭subscript𝑇2𝐭𝐭subscript𝖵𝖺𝗋𝗌2subscript𝜔2s=[T_{1}\{\mathbf{t}=T_{1,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars_{1}}\},% \omega_{1}]|[T_{2}\{\mathbf{t}=T_{2,\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars_{% 2}}\},\omega_{2}]italic_s = [ italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 1 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT sansserif_1 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT 2 , bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT sansserif_2 end_POSTSUBSCRIPT } , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ] exposes variable 𝐭𝖵𝖺𝗋𝗌𝟣superscript𝐭subscript𝖵𝖺𝗋𝗌1\mathbf{t}^{\prime}\in\mathsf{Vars_{1}}bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ sansserif_Vars start_POSTSUBSCRIPT sansserif_1 end_POSTSUBSCRIPT if T1=𝐭subscript𝑇1superscript𝐭T_{1}=\mathbf{t}^{\prime}italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT = bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. Moreover, we denote transition systems paths starting from a given configuration s𝑠sitalic_s, i.e. finite sequences of transitions sα1s1α2s2αnsn𝑠superscriptsubscript𝛼1subscript𝑠1superscriptsubscript𝛼2subscript𝑠2superscriptsubscript𝛼𝑛subscript𝑠𝑛s\,\mathop{\longrightarrow}\limits^{\alpha_{1}}\,s_{1}\,\mathop{% \longrightarrow}\limits^{\alpha_{2}}\,s_{2}\dots\,\mathop{\longrightarrow}% \limits^{\alpha_{n}}\,s_{n}italic_s ⟶ start_POSTSUPERSCRIPT italic_α start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT end_POSTSUPERSCRIPT italic_s start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⟶ start_POSTSUPERSCRIPT italic_α start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT end_POSTSUPERSCRIPT italic_s start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT … ⟶ start_POSTSUPERSCRIPT italic_α start_POSTSUBSCRIPT italic_n end_POSTSUBSCRIPT end_POSTSUPERSCRIPT italic_s start_POSTSUBSCRIPT italic_n end_POSTSUBSCRIPT (where αisubscript𝛼𝑖\alpha_{i}italic_α start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT decorations can be ε𝜀\varepsilonitalic_ε in case of non decorated \rightarrow transitions), by means of strings α1,s1α2,s2αn,snsubscript𝛼1subscript𝑠1subscript𝛼2subscript𝑠2subscript𝛼𝑛subscript𝑠𝑛\langle\alpha_{1},s_{1}\rangle\langle\alpha_{2},s_{2}\rangle\dots\langle\alpha% _{n},s_{n}\rangle⟨ italic_α start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , italic_s start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⟩ ⟨ italic_α start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , italic_s start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ⟩ … ⟨ italic_α start_POSTSUBSCRIPT italic_n end_POSTSUBSCRIPT , italic_s start_POSTSUBSCRIPT italic_n end_POSTSUBSCRIPT ⟩ (strings over pairs α,ssuperscript𝛼superscript𝑠\langle\alpha^{\prime},s^{\prime}\rangle⟨ italic_α start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟩ with αsuperscript𝛼\alpha^{\prime}italic_α start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT being a decoration or ε𝜀\varepsilonitalic_ε and ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT a configuration).

Assuming 𝖾𝗌𝗇(T)=T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝖾𝗌𝗇𝑇subscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌\mathsf{esn}(T)=T_{\mathsf{init}}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in% \mathsf{Vars}\}sansserif_esn ( italic_T ) = italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars }, we now construct an indexing on the variables in the subset 𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌\mathsf{Vars^{\prime}}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT of 𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌\mathsf{Vars}sansserif_Vars, which includes variables 𝐭𝐭\mathbf{t}bold_t such that: a configuration s𝑠sitalic_s that exposes 𝐭𝐭\mathbf{t}bold_t is reachable from the initial configuration [𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵ[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon][ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ]. We proceed as follows. If 𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌\mathsf{Vars^{\prime}}\neq\emptysetsansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≠ ∅, then we consider any reachable configuration s𝑠sitalic_s that exposes some variable 𝐭𝖵𝖺𝗋𝗌𝐭𝖵𝖺𝗋𝗌\mathbf{t}\in\mathsf{Vars}bold_t ∈ sansserif_Vars. Since [𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵ[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon][ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ] is a correct composition, the configuration s𝑠sitalic_s must reach a configuration ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that ssuperscript𝑠square-roots^{\prime}\surditalic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT √. We consider the path from s𝑠sitalic_s to ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and the last configuration s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT of such a path that exposes a variable. We denote such a variable with 𝐭1subscript𝐭1\mathbf{t}_{1}bold_t start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT, the configuration s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT that exposes it with s1subscript𝑠1s_{1}italic_s start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT, and the path (string) from s1subscript𝑠1s_{1}italic_s start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT that leads to ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT (part of the path from s𝑠sitalic_s to ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT considered above) with 𝗉𝖺𝗍𝗁1subscript𝗉𝖺𝗍𝗁1\mathsf{path}_{1}sansserif_path start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT. In any subsequent k𝑘kitalic_k-th step, with k2𝑘2k\geq 2italic_k ≥ 2, we consider the set 𝖵𝖺𝗋𝗌k=𝖵𝖺𝗋𝗌{𝐭hh<k}subscript𝖵𝖺𝗋𝗌𝑘superscript𝖵𝖺𝗋𝗌conditional-setsubscript𝐭𝑘\mathsf{Vars}_{k}=\mathsf{Vars^{\prime}}-\{\mathbf{t}_{h}\mid h<k\}sansserif_Vars start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT = sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT - { bold_t start_POSTSUBSCRIPT italic_h end_POSTSUBSCRIPT ∣ italic_h < italic_k }. If 𝖵𝖺𝗋𝗌ksubscript𝖵𝖺𝗋𝗌𝑘\mathsf{Vars}_{k}\neq\emptysetsansserif_Vars start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ≠ ∅, then we consider any reachable configuration s𝑠sitalic_s that exposes some variable 𝐭𝖵𝖺𝗋𝗌k𝐭subscript𝖵𝖺𝗋𝗌𝑘\mathbf{t}\in\mathsf{Vars}_{k}bold_t ∈ sansserif_Vars start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT. Since [𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵ[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon][ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ] is a correct composition, the configuration s𝑠sitalic_s must reach a configuration ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that ssuperscript𝑠square-roots^{\prime}\surditalic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT √. We consider the path from s𝑠sitalic_s to ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and the first configuration s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT of such a path that either exposes a variable in {𝐭hh<k}conditional-setsubscript𝐭𝑘\{\mathbf{t}_{h}\mid h<k\}{ bold_t start_POSTSUBSCRIPT italic_h end_POSTSUBSCRIPT ∣ italic_h < italic_k } or is such that s′′superscript𝑠′′square-roots^{\prime\prime}\surditalic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT √. Again we consider the path from s𝑠sitalic_s to s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT and the last configuration s′′′superscript𝑠′′′s^{\prime\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT of such a path that: is different from s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT and exposes a variable (such a variable must exist, because s𝑠sitalic_s exposes a variable, and belong to 𝖵𝖺𝗋𝗌ksubscript𝖵𝖺𝗋𝗌𝑘\mathsf{Vars}_{k}sansserif_Vars start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT because of the way we have selected s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT). We denote such a variable with 𝐭ksubscript𝐭𝑘\mathbf{t}_{k}bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT, the configuration s′′′superscript𝑠′′′s^{\prime\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT that exposes it with sksubscript𝑠𝑘s_{k}italic_s start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT, and the path (string) from sksubscript𝑠𝑘s_{k}italic_s start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT that leads to s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT (part of the path from s𝑠sitalic_s to s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT considered above) with 𝗉𝖺𝗍𝗁ksubscript𝗉𝖺𝗍𝗁𝑘\mathsf{path}_{k}sansserif_path start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT.

We now consider terms Tksubscriptsuperscript𝑇𝑘T^{\prime}_{k}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT for each variable 𝐭k𝖵𝖺𝗋𝗌subscript𝐭𝑘superscript𝖵𝖺𝗋𝗌\mathbf{t}_{k}\in\mathsf{Vars^{\prime}}bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. We build Tksubscriptsuperscript𝑇𝑘T^{\prime}_{k}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT terms inductively by taking Tk=𝗍𝖾𝗋𝗆(T𝐭k,sk,𝗉𝖺𝗍𝗁k)subscriptsuperscript𝑇𝑘𝗍𝖾𝗋𝗆subscript𝑇subscript𝐭𝑘subscript𝑠𝑘subscript𝗉𝖺𝗍𝗁𝑘T^{\prime}_{k}=\mathsf{term}(T_{\mathbf{t}_{k}},s_{k},\mathsf{path}_{k})italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT = sansserif_term ( italic_T start_POSTSUBSCRIPT bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT end_POSTSUBSCRIPT , italic_s start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT , sansserif_path start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ), where 𝗍𝖾𝗋𝗆(T,s,𝗈𝗉𝗍𝗉𝖺𝗍𝗁)𝗍𝖾𝗋𝗆superscript𝑇𝑠𝗈𝗉𝗍𝗉𝖺𝗍𝗁\mathsf{term}(T^{\prime},s,\mathsf{optpath})sansserif_term ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_s , sansserif_optpath ), with 𝗈𝗉𝗍𝗉𝖺𝗍𝗁𝗈𝗉𝗍𝗉𝖺𝗍𝗁\mathsf{optpath}sansserif_optpath being either a 𝗉𝖺𝗍𝗁𝗉𝖺𝗍𝗁\mathsf{path}sansserif_path or * (that represents being outside the path), is defined as follows.

  • 𝗍𝖾𝗋𝗆(𝐭,s,ε)=𝐭𝗍𝖾𝗋𝗆𝐭𝑠𝜀𝐭\mathsf{term}(\mathbf{t},s,\varepsilon)=\mathbf{t}sansserif_term ( bold_t , italic_s , italic_ε ) = bold_t

  • 𝗍𝖾𝗋𝗆(𝐞𝐧𝐝,s,ε)=𝐞𝐧𝐝𝗍𝖾𝗋𝗆𝐞𝐧𝐝𝑠𝜀𝐞𝐧𝐝\mathsf{term}(\mathbf{end},s,\varepsilon)=\mathbf{end}sansserif_term ( bold_end , italic_s , italic_ε ) = bold_end

  • 𝗍𝖾𝗋𝗆(&{li:Ti}iI,s,lj,s𝗉𝖺𝗍𝗁)=&{lj:𝗍𝖾𝗋𝗆(Tj,s,𝗉𝖺𝗍𝗁)}𝗍𝖾𝗋𝗆subscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼𝑠subscript𝑙𝑗superscript𝑠𝗉𝖺𝗍𝗁conditional-setsubscript𝑙𝑗𝗍𝖾𝗋𝗆subscript𝑇𝑗superscript𝑠𝗉𝖺𝗍𝗁\mathsf{term}(\&\{{l}_{i}:{T}_{i}\}_{i\in I},s,\langle l_{j},s^{\prime}\rangle% \mathsf{path})=\&\{{l_{j}}:{\mathsf{term}(T_{j},s^{\prime},\mathsf{path})}\}sansserif_term ( & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT , italic_s , ⟨ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟩ sansserif_path ) = & { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : sansserif_term ( italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , sansserif_path ) }

  • 𝗍𝖾𝗋𝗆({li:Ti}iI,s,lj¯,s𝗉𝖺𝗍𝗁)={li:Ti}iI𝗍𝖾𝗋𝗆direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼𝑠¯subscript𝑙𝑗superscript𝑠𝗉𝖺𝗍𝗁direct-sumsubscriptconditional-setsubscript𝑙𝑖subscriptsuperscript𝑇𝑖𝑖𝐼\mathsf{term}(\oplus\{{l}_{i}:{T}_{i}\}_{i\in I},s,\langle\overline{l_{j}},s^{% \prime}\rangle\mathsf{path})=\oplus\{{l}_{i}:{T^{\prime}}_{i}\}_{i\in I}sansserif_term ( ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT , italic_s , ⟨ over¯ start_ARG italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT end_ARG , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟩ sansserif_path ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT
    where Tj=𝗍𝖾𝗋𝗆(Tj,s,𝗉𝖺𝗍𝗁)subscriptsuperscript𝑇𝑗𝗍𝖾𝗋𝗆subscript𝑇𝑗superscript𝑠𝗉𝖺𝗍𝗁T^{\prime}_{j}\!=\!\mathsf{term}(T_{j},s^{\prime},\mathsf{path})italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT = sansserif_term ( italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , sansserif_path ) and, for all iI𝑖𝐼i\!\in\!Iitalic_i ∈ italic_Iij𝑖𝑗i\!\neq\!jitalic_i ≠ italic_j: Ti=𝗍𝖾𝗋𝗆(Ti,si,)subscriptsuperscript𝑇𝑖𝗍𝖾𝗋𝗆subscript𝑇𝑖subscript𝑠𝑖T^{\prime}_{i}\!=\!\mathsf{term}(T_{i},s_{i},*)italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT = sansserif_term ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_s start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , ∗ ) with sli¯si𝑠superscript¯subscript𝑙𝑖subscript𝑠𝑖s\,\mathop{\longrightarrow}\limits^{\overline{l_{i}}}\,s_{i}italic_s ⟶ start_POSTSUPERSCRIPT over¯ start_ARG italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT end_ARG end_POSTSUPERSCRIPT italic_s start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT

  • 𝗍𝖾𝗋𝗆(T,s,ε,s𝗉𝖺𝗍𝗁)=𝗍𝖾𝗋𝗆(T,s,𝗉𝖺𝗍𝗁)𝗍𝖾𝗋𝗆superscript𝑇𝑠𝜀superscript𝑠𝗉𝖺𝗍𝗁𝗍𝖾𝗋𝗆superscript𝑇superscript𝑠𝗉𝖺𝗍𝗁\mathsf{term}(T^{\prime},s,\langle\varepsilon,s^{\prime}\rangle\mathsf{path})=% \mathsf{term}(T^{\prime},s^{\prime},\mathsf{path})sansserif_term ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_s , ⟨ italic_ε , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟩ sansserif_path ) = sansserif_term ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , sansserif_path )

  • 𝗍𝖾𝗋𝗆(𝐭,s,)=𝐭𝗍𝖾𝗋𝗆𝐭𝑠𝐭\mathsf{term}(\mathbf{t},s,*)=\mathbf{t}sansserif_term ( bold_t , italic_s , ∗ ) = bold_t

  • 𝗍𝖾𝗋𝗆(𝐞𝐧𝐝,s,)=𝐞𝐧𝐝𝗍𝖾𝗋𝗆𝐞𝐧𝐝𝑠𝐞𝐧𝐝\mathsf{term}(\mathbf{end},s,*)=\mathbf{end}sansserif_term ( bold_end , italic_s , ∗ ) = bold_end

  • 𝗍𝖾𝗋𝗆(&{li:Ti}iI,s,)=&{lj:𝗍𝖾𝗋𝗆(Tj,sj,)}𝗍𝖾𝗋𝗆subscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼𝑠conditional-setsubscript𝑙𝑗𝗍𝖾𝗋𝗆subscript𝑇𝑗subscript𝑠𝑗\mathsf{term}(\&\{{l}_{i}:{T}_{i}\}_{i\in I},s,*)=\&\{{l_{j}}:{\mathsf{term}(T% _{j},s_{j},*)}\}sansserif_term ( & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT , italic_s , ∗ ) = & { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : sansserif_term ( italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , italic_s start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , ∗ ) } if s𝑠sitalic_s has some lsuperscript𝑙\,\mathop{\longrightarrow}\limits^{l}\,⟶ start_POSTSUPERSCRIPT italic_l end_POSTSUPERSCRIPT transition
    where j𝑗jitalic_j is any iI𝑖𝐼i\in Iitalic_i ∈ italic_I such that sljsj𝑠superscriptsubscript𝑙𝑗subscript𝑠𝑗s\,\mathop{\longrightarrow}\limits^{l_{j}}\,s_{j}italic_s ⟶ start_POSTSUPERSCRIPT italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT end_POSTSUPERSCRIPT italic_s start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT

  • 𝗍𝖾𝗋𝗆({li:Ti}iI,s,)={li:𝗍𝖾𝗋𝗆(Ti,si,)i}iI𝗍𝖾𝗋𝗆direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼𝑠direct-sumsubscriptconditional-setsubscript𝑙𝑖𝗍𝖾𝗋𝗆subscriptsubscript𝑇𝑖subscript𝑠𝑖𝑖𝑖𝐼\mathsf{term}(\oplus\{{l}_{i}:{T}_{i}\}_{i\in I},s,*)=\oplus\{{l}_{i}:{\mathsf% {term}(T_{i},s_{i},*)}_{i}\}_{i\in I}sansserif_term ( ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT , italic_s , ∗ ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : sansserif_term ( italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_s start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , ∗ ) start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT if s𝑠sitalic_s has some l¯superscript¯𝑙\,\mathop{\longrightarrow}\limits^{\overline{l}}\,⟶ start_POSTSUPERSCRIPT over¯ start_ARG italic_l end_ARG end_POSTSUPERSCRIPT transition
    where, for all iI𝑖𝐼i\!\in\!Iitalic_i ∈ italic_I, slisi𝑠superscriptsubscript𝑙𝑖subscript𝑠𝑖s\,\mathop{\longrightarrow}\limits^{l_{i}}\,s_{i}italic_s ⟶ start_POSTSUPERSCRIPT italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT end_POSTSUPERSCRIPT italic_s start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT

  • 𝗍𝖾𝗋𝗆(T,s,)=𝗍𝖾𝗋𝗆(T,s,)𝗍𝖾𝗋𝗆superscript𝑇𝑠𝗍𝖾𝗋𝗆superscript𝑇superscript𝑠\mathsf{term}(T^{\prime},s,*)=\mathsf{term}(T^{\prime},s^{\prime},*)sansserif_term ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_s , ∗ ) = sansserif_term ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , ∗ ) if T{𝐭,𝐞𝐧𝐝}superscript𝑇𝐭𝐞𝐧𝐝T^{\prime}\notin\{\mathbf{t},\mathbf{end}\}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∉ { bold_t , bold_end } and s𝑠sitalic_s has neither lsuperscript𝑙\,\mathop{\longrightarrow}\limits^{l}\,⟶ start_POSTSUPERSCRIPT italic_l end_POSTSUPERSCRIPT nor l¯superscript¯𝑙\,\mathop{\longrightarrow}\limits^{\overline{l}}\,⟶ start_POSTSUPERSCRIPT over¯ start_ARG italic_l end_ARG end_POSTSUPERSCRIPT transitions
    where ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is the first configuration having some lsuperscript𝑙\,\mathop{\longrightarrow}\limits^{l}\,⟶ start_POSTSUPERSCRIPT italic_l end_POSTSUPERSCRIPT transition or some l¯superscript¯𝑙\,\mathop{\longrightarrow}\limits^{\overline{l}}\,⟶ start_POSTSUPERSCRIPT over¯ start_ARG italic_l end_ARG end_POSTSUPERSCRIPT transition in the path from s𝑠sitalic_s to a configuration s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that s′′superscript𝑠′′square-roots^{\prime\prime}\surditalic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT √ (such a path must exist because [𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵ[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon][ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ] is a correct composition)

where we use ε𝜀\varepsilonitalic_ε to represent the empty string.

We also take T𝗂𝗇𝗂𝗍=𝗍𝖾𝗋𝗆(T𝗂𝗇𝗂𝗍,[𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ],)subscriptsuperscript𝑇𝗂𝗇𝗂𝗍𝗍𝖾𝗋𝗆subscript𝑇𝗂𝗇𝗂𝗍conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵT^{\prime}_{\mathsf{init}}=\mathsf{term}(T_{\mathsf{init}},[\mathsf{esn}(T),% \epsilon]|[\mathsf{esn}(S),\epsilon],*)italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT = sansserif_term ( italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT , [ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ] , ∗ ).

We now have that T𝗂𝗇𝗂𝗍{𝐭k=Tk𝐭k𝖵𝖺𝗋𝗌}subscriptsuperscript𝑇𝗂𝗇𝗂𝗍conditional-setsubscript𝐭𝑘subscriptsuperscript𝑇𝑘subscript𝐭𝑘superscript𝖵𝖺𝗋𝗌T^{\prime}_{\mathsf{init}}\{\mathbf{t}_{k}=T^{\prime}_{k}\mid\mathbf{t}_{k}\in% \mathsf{Vars}^{\prime}\}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT = italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∣ bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } is a session type in equation notation: 𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌\mathsf{Vars}^{\prime}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT must include all variables in 𝖿𝗋𝖾𝖾(T𝗂𝗇𝗂𝗍)𝖿𝗋𝖾𝖾subscriptsuperscript𝑇𝗂𝗇𝗂𝗍\mathsf{free}(T^{\prime}_{\mathsf{init}})sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT ) and also in 𝖿𝗋𝖾𝖾(Tk)𝖿𝗋𝖾𝖾subscriptsuperscript𝑇𝑘\mathsf{free}(T^{\prime}_{k})sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ) for all 𝐭k𝖵𝖺𝗋𝗌subscript𝐭𝑘superscript𝖵𝖺𝗋𝗌\mathbf{t}_{k}\in\mathsf{Vars}^{\prime}bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT because, otherwise, a configuration s𝑠sitalic_s exposing the variable that is not included in 𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌\mathsf{Vars}^{\prime}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT would have been reachable from the initial configuration [𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵ[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon][ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ] (which contradicts the definition of 𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌\mathsf{Vars}^{\prime}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT). Moreover, due to the way 𝗍𝖾𝗋𝗆𝗍𝖾𝗋𝗆\mathsf{term}sansserif_term is defined, T𝗂𝗇𝗂𝗍{𝐭k=Tk𝐭k𝖵𝖺𝗋𝗌}subscriptsuperscript𝑇𝗂𝗇𝗂𝗍conditional-setsubscript𝐭𝑘subscriptsuperscript𝑇𝑘subscript𝐭𝑘superscript𝖵𝖺𝗋𝗌T^{\prime}_{\mathsf{init}}\{\mathbf{t}_{k}=T^{\prime}_{k}\mid\mathbf{t}_{k}\in% \mathsf{Vars}^{\prime}\}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT = italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∣ bold_t start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } is obtained from T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}subscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌T_{\mathsf{init}}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\}italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } by performing input replacement that yields input prefixes with single inputs. Finally, being sksubscript𝑠𝑘s_{k}italic_s start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT the last configuration exposing a variable inside a path ending with a configuration s𝑠sitalic_s that either exposes a variable in {𝐭hh<k}conditional-setsubscript𝐭𝑘\{\mathbf{t}_{h}\mid h<k\}{ bold_t start_POSTSUBSCRIPT italic_h end_POSTSUBSCRIPT ∣ italic_h < italic_k } (and not having previous configurations exposing such variables) or is such that s𝑠square-roots\surditalic_s √, each of the Tksubscriptsuperscript𝑇𝑘T^{\prime}_{k}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT satisfies the constraint 𝐞𝐧𝐝Tk𝐭h:h<k𝐭h𝖿𝗋𝖾𝖾(Tk):𝐞𝐧𝐝subscriptsuperscript𝑇𝑘subscript𝐭𝑘subscript𝐭𝖿𝗋𝖾𝖾subscriptsuperscript𝑇𝑘\mathbf{end}\!\in\!T^{\prime}_{k}\vee\exists\mathbf{t}_{h}\!:\!h<k\wedge% \mathbf{t}_{h}\!\in\!\mathsf{free}(T^{\prime}_{k})bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ∨ ∃ bold_t start_POSTSUBSCRIPT italic_h end_POSTSUBSCRIPT : italic_h < italic_k ∧ bold_t start_POSTSUBSCRIPT italic_h end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ).

Theorem 18.

If T𝑇Titalic_T 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl then there exists a session type S𝑆Sitalic_S such that T𝑇Titalic_T and S𝑆Sitalic_S are compliant.

Proof A.6.

If T𝑇Titalic_T 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl then 𝖾𝗌𝗇(T)=T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}𝖾𝗌𝗇𝑇subscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌\mathsf{esn}(T)=T_{\mathsf{init}}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in% \mathsf{Vars}\}sansserif_esn ( italic_T ) = italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } 𝖼𝗍𝗋𝗅𝖼𝗍𝗋𝗅\,\mathsf{ctrl}sansserif_ctrl. That is, there exists an input prefix replacement that yields a session type T𝗂𝗇𝗂𝗍{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌}subscriptsuperscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭subscriptsuperscript𝑇𝐭𝐭superscript𝖵𝖺𝗋𝗌T^{\prime}_{\mathsf{init}}\{\mathbf{t}=T^{\prime}_{\mathbf{t}}\mid\mathbf{t}% \in\mathsf{Vars}^{\prime}\}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } such that 𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌𝖵𝖺𝗋𝗌\mathsf{Vars}^{\prime}\subseteq\mathsf{Vars}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊆ sansserif_Vars (and in both term T𝗂𝗇𝗂𝗍𝗌𝗂𝗇(T𝗂𝗇𝗂𝗍)subscriptsuperscript𝑇𝗂𝗇𝗂𝗍𝗌𝗂𝗇subscript𝑇𝗂𝗇𝗂𝗍T^{\prime}_{\mathsf{init}}\in\mathsf{sin}(T_{\mathsf{init}})italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT ∈ sansserif_sin ( italic_T start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT ) and all terms T𝐭𝗌𝗂𝗇(T𝐭)subscriptsuperscript𝑇𝐭𝗌𝗂𝗇subscript𝑇𝐭T^{\prime}_{\mathbf{t}}\in\mathsf{sin}(T_{\mathbf{t}})italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∈ sansserif_sin ( italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ), with 𝐭𝖵𝖺𝗋𝗌𝐭superscript𝖵𝖺𝗋𝗌\mathbf{t}\in\mathsf{Vars}^{\prime}bold_t ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, all input prefixes have a single label) and that satisfies the 𝗈𝗄𝗈𝗄\,\mathsf{ok}sansserif_ok predicate, i.e. there exists an indexing 𝐭isubscript𝐭𝑖\mathbf{t}_{i}bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT of the 𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌\mathsf{Vars}^{\prime}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT variables, such that: 𝐞𝐧𝐝T𝐭i𝐭j:j<i𝐭j𝖿𝗋𝖾𝖾(T𝐭i):𝐞𝐧𝐝subscriptsuperscript𝑇subscript𝐭𝑖subscript𝐭𝑗𝑗𝑖subscript𝐭𝑗𝖿𝗋𝖾𝖾subscriptsuperscript𝑇subscript𝐭𝑖\mathbf{end}\!\in\!T^{\prime}_{\mathbf{t}_{i}}\vee\exists\mathbf{t}_{j}\!:\!j<% i\wedge\mathbf{t}_{j}\!\in\!\mathsf{free}(T^{\prime}_{\mathbf{t}_{i}})bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT end_POSTSUBSCRIPT ∨ ∃ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_j < italic_i ∧ bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ∈ sansserif_free ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT end_POSTSUBSCRIPT ). We assume set 𝖵𝖺𝗋𝗌superscript𝖵𝖺𝗋𝗌\mathsf{Vars}^{\prime}sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT to be minimal, i.e. to not include any defined but unused variable name and we take S𝑆Sitalic_S to be the unique session type such that 𝖾𝗌𝗇(S)=T𝗂𝗇𝗂𝗍¯{𝐭=T𝐭¯𝐭𝖵𝖺𝗋𝗌}𝖾𝗌𝗇𝑆¯subscriptsuperscript𝑇𝗂𝗇𝗂𝗍conditional-set𝐭¯subscriptsuperscript𝑇𝐭𝐭superscript𝖵𝖺𝗋𝗌\mathsf{esn}(S)=\overline{T^{\prime}_{\mathsf{init}}}\{\mathbf{t}=\overline{T^% {\prime}_{\mathbf{t}}}\mid\mathbf{t}\in\mathsf{Vars}^{\prime}\}sansserif_esn ( italic_S ) = over¯ start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT end_ARG { bold_t = over¯ start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT end_ARG ∣ bold_t ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT }.

In the following we will consider configurations [T1{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌},ω1]|[T2{𝐭=T𝐭¯𝐭𝖵𝖺𝗋𝗌},ω2]conditionalsubscript𝑇1conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌subscript𝜔1subscript𝑇2conditional-set𝐭¯subscriptsuperscript𝑇𝐭𝐭superscript𝖵𝖺𝗋𝗌subscript𝜔2[T_{1}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in\mathsf{Vars}\},\omega_{1}]|% [T_{2}\{\mathbf{t}=\overline{T^{\prime}_{\mathbf{t}}}\mid\mathbf{t}\in\mathsf{% Vars}^{\prime}\},\omega_{2}][ italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } , italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ] | [ italic_T start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT { bold_t = over¯ start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT end_ARG ∣ bold_t ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } , italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ] that are reachable from the initial configuration s𝗂𝗇𝗂𝗍=[𝖾𝗌𝗇(T),ϵ]|[𝖾𝗌𝗇(S),ϵ]subscript𝑠𝗂𝗇𝗂𝗍conditional𝖾𝗌𝗇𝑇italic-ϵ𝖾𝗌𝗇𝑆italic-ϵs_{\mathsf{init}}=[\mathsf{esn}(T),\epsilon]|[\mathsf{esn}(S),\epsilon]italic_s start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT = [ sansserif_esn ( italic_T ) , italic_ϵ ] | [ sansserif_esn ( italic_S ) , italic_ϵ ]. We say that any such configuration exposes variable 𝐭𝖵𝖺𝗋𝗌superscript𝐭𝖵𝖺𝗋𝗌\mathbf{t}^{\prime}\in\mathsf{Vars}bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ∈ sansserif_Vars if T1=𝐭subscript𝑇1superscript𝐭T_{1}=\mathbf{t}^{\prime}italic_T start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT = bold_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. Now, given any configuration s𝑠sitalic_s reachable from the initial configuration s𝗂𝗇𝗂𝗍subscript𝑠𝗂𝗇𝗂𝗍s_{\mathsf{init}}italic_s start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT, we have that s𝑠sitalic_s is such that:

  • ω1=ϵω2=ϵsubscript𝜔1italic-ϵsubscript𝜔2italic-ϵ\omega_{1}=\epsilon\vee\omega_{2}=\epsilonitalic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT = italic_ϵ ∨ italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT = italic_ϵ

  • There exists a configuration sϵsubscript𝑠italic-ϵs_{\epsilon}italic_s start_POSTSUBSCRIPT italic_ϵ end_POSTSUBSCRIPT, which is reached from s𝑠sitalic_s with the transitions originated by performing either the non-empty ω1subscript𝜔1\omega_{1}italic_ω start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT sequence of inputs in the lefthand type or the non-empty sequence ω2subscript𝜔2\omega_{2}italic_ω start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT of inputs in the righthand type, such that sϵ=[T1{𝐭=T𝐭𝐭𝖵𝖺𝗋𝗌},ϵ]|[T2¯{𝐭=T𝐭¯𝐭𝖵𝖺𝗋𝗌},ϵ]subscript𝑠italic-ϵconditionalsubscriptsuperscript𝑇1conditional-set𝐭subscript𝑇𝐭𝐭𝖵𝖺𝗋𝗌italic-ϵ¯subscriptsuperscript𝑇2conditional-set𝐭¯subscriptsuperscript𝑇𝐭𝐭superscript𝖵𝖺𝗋𝗌italic-ϵs_{\epsilon}=[T^{\prime}_{1}\{\mathbf{t}=T_{\mathbf{t}}\mid\mathbf{t}\in% \mathsf{Vars}\},\epsilon]|[\overline{T^{\prime}_{2}}\{\mathbf{t}=\overline{T^{% \prime}_{\mathbf{t}}}\mid\mathbf{t}\in\mathsf{Vars}^{\prime}\},\epsilon]italic_s start_POSTSUBSCRIPT italic_ϵ end_POSTSUBSCRIPT = [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT { bold_t = italic_T start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT ∣ bold_t ∈ sansserif_Vars } , italic_ϵ ] | [ over¯ start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT end_ARG { bold_t = over¯ start_ARG italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t end_POSTSUBSCRIPT end_ARG ∣ bold_t ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } , italic_ϵ ], with T2𝗌𝗂𝗇(T1)subscriptsuperscript𝑇2𝗌𝗂𝗇subscriptsuperscript𝑇1T^{\prime}_{2}\in\mathsf{sin}(T^{\prime}_{1})italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ∈ sansserif_sin ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ).

This property of s𝑠sitalic_s is, indeed, an invariant property of all configurations reachable from the initial configuration s𝗂𝗇𝗂𝗍subscript𝑠𝗂𝗇𝗂𝗍s_{\mathsf{init}}italic_s start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT in that: it is satisfied by s𝗂𝗇𝗂𝗍subscript𝑠𝗂𝗇𝗂𝗍s_{\mathsf{init}}italic_s start_POSTSUBSCRIPT sansserif_init end_POSTSUBSCRIPT itself and it is preserved both by transitions originated from outputs of the lefthand or righthand type (which, for a configuration satisfying the above property, can be done only if its own queue is empty, and have the effect of enqueuing in the righthand or lefthand type, respectively, a symbol that it can then, dually, dequeue with an input) and by transitions originated from inputs of the lefthand or righthand type (which just make the already existing input transition sequence to sϵsubscript𝑠italic-ϵs_{\epsilon}italic_s start_POSTSUBSCRIPT italic_ϵ end_POSTSUBSCRIPT shorter).

We now notice that it is possible to reach, from sϵsubscript𝑠italic-ϵs_{\epsilon}italic_s start_POSTSUBSCRIPT italic_ϵ end_POSTSUBSCRIPT, by performing outputs of the lefthand or righthand type immediately followed by inputs dually executed by the righthand or lefthand type, respectively: either a configuration ssuperscript𝑠s^{\prime}italic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that ssuperscript𝑠square-roots^{\prime}\surditalic_s start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT √ (in case 𝐞𝐧𝐝T2𝐞𝐧𝐝subscriptsuperscript𝑇2\mathbf{end}\in T^{\prime}_{2}bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT), or a configuration exposing an indexed variable 𝐭i𝖵𝖺𝗋𝗌subscript𝐭𝑖superscript𝖵𝖺𝗋𝗌\mathbf{t}_{i}\in\mathsf{Vars}^{\prime}bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. In the latter case, we can, similarly, reach: either a configuration s′′superscript𝑠′′s^{\prime\prime}italic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that s′′superscript𝑠′′square-roots^{\prime\prime}\surditalic_s start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT √ (in case 𝐞𝐧𝐝T𝐭i𝐞𝐧𝐝subscriptsuperscript𝑇subscript𝐭𝑖\mathbf{end}\in T^{\prime}_{\mathbf{t}_{i}}bold_end ∈ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT bold_t start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT end_POSTSUBSCRIPT), or a configuration exposing an indexed variable 𝐭j𝖵𝖺𝗋𝗌subscript𝐭𝑗superscript𝖵𝖺𝗋𝗌\mathbf{t}_{j}\in\mathsf{Vars}^{\prime}bold_t start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ∈ sansserif_Vars start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with j<i𝑗𝑖j<iitalic_j < italic_i. In the latter case, we repeat, again, the same step: we are guaranteed to eventually meet the case in which a square-root\surd configuration is reached in that variable indexes strictly decrease at each step. We thus have that 𝖾𝗌𝗇(T)𝖾𝗌𝗇𝑇\mathsf{esn}(T)sansserif_esn ( italic_T ) and 𝖾𝗌𝗇(S)𝖾𝗌𝗇𝑆\mathsf{esn}(S)sansserif_esn ( italic_S ) are compliant, hence T𝑇Titalic_T and S𝑆Sitalic_S are compliant.

A.3. Soundness of Fair Asynchronous Subtyping w.r.t. Fair Refinement

Lemma 19.

Consider the session type T=𝒜[{lj:Tkj}jJ]kK𝑇𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscript𝑇𝑘𝑗𝑗𝐽𝑘𝐾T=\mathcal{A}[{\oplus\{{l}_{j}:{T_{k}}_{j}\}_{j\in J}}]^{k\in K}italic_T = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT. Let P2=[T,ωT]|[S,ωS]subscript𝑃2conditional𝑇subscript𝜔𝑇𝑆subscript𝜔𝑆P_{2}=[T,\omega_{T}]|[S,\omega_{S}]italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT = [ italic_T , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] and P1i=[𝒜[Tki]kK,ωT]|[S,ωSli]superscriptsubscript𝑃1𝑖conditional𝒜superscriptdelimited-[]subscript𝑇𝑘𝑖𝑘𝐾subscript𝜔𝑇𝑆subscript𝜔𝑆subscript𝑙𝑖P_{1}^{i}=[\mathcal{A}[{T_{ki}}]^{k\in K},\omega_{T}]|[S,\omega_{S}\!\cdot\!l_% {i}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT = [ caligraphic_A [ italic_T start_POSTSUBSCRIPT italic_k italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ], for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J. If P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is a correct composition then one of the following holds:

  • 𝒜𝒜\mathcal{A}caligraphic_A does not contain any input branching and P2P1isuperscriptabsentsubscript𝑃2superscriptsubscript𝑃1𝑖P_{2}\stackrel{{\scriptstyle}}{{\rightarrow}}P_{1}^{i}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT, for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J;

  • 𝒜𝒜\mathcal{A}caligraphic_A contains an input branching and P1isuperscriptsubscript𝑃1𝑖P_{1}^{i}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT (for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J) and P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT have at least one outgoing transition.
    For every possible transition P1iP1superscriptabsentsuperscriptsubscript𝑃1𝑖superscriptsubscript𝑃1P_{1}^{i}\stackrel{{\scriptstyle}}{{\rightarrow}}P_{1}^{\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT we have that one of the following holds:

    1. (1)

      P1isuperscriptsubscript𝑃1𝑖P_{1}^{i}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT does not consume the label lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT and there exist 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, W𝑊Witalic_W, Twjsubscriptsuperscript𝑇𝑤𝑗T^{\prime}_{wj}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_w italic_j end_POSTSUBSCRIPT (for every wW𝑤𝑊w\in Witalic_w ∈ italic_W, jJ𝑗𝐽j\in Jitalic_j ∈ italic_J), Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, ωTsuperscriptsubscript𝜔𝑇\omega_{T}^{\prime}italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and ωSsuperscriptsubscript𝜔𝑆\omega_{S}^{\prime}italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT s.t. P1=[𝒜[Twi]wW,ωT]|[S,ωSli]superscriptsubscript𝑃1conditionalsuperscript𝒜superscriptdelimited-[]subscriptsuperscript𝑇𝑤𝑖𝑤𝑊superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆subscript𝑙𝑖P_{1}^{\prime}=[\mathcal{A^{\prime}}[{T^{\prime}_{wi}}]^{w\in W},\omega_{T}^{% \prime}]{|}[S^{\prime},\omega_{S}^{\prime}\!\cdot\!l_{i}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = [ caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_w italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_w ∈ italic_W end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ] and
      P2[𝒜[{lj:Twj}jJ]wW,ωT]|[S,ωS]superscriptabsentsubscript𝑃2conditionalsuperscript𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscriptsuperscript𝑇𝑤𝑗𝑗𝐽𝑤𝑊superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆P_{2}\stackrel{{\scriptstyle}}{{\rightarrow}}[\mathcal{A^{\prime}}[{\oplus\{{l% }_{j}:{T^{\prime}_{w}}_{j}\}_{j\in J}}]^{w\in W},\omega_{T}^{\prime}]{|}[S^{% \prime},\omega_{S}^{\prime}]italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_w ∈ italic_W end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ];

    2. (2)

      P1isuperscriptsubscript𝑃1𝑖P_{1}^{i}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT consumes the label lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT, hence P1=[𝒜[Tki]kK,ωT]|[S,ωS]superscriptsubscript𝑃1conditional𝒜superscriptdelimited-[]subscript𝑇𝑘𝑖𝑘𝐾subscript𝜔𝑇superscript𝑆subscript𝜔𝑆P_{1}^{\prime}=[\mathcal{A}[{T_{ki}}]^{k\in K},\omega_{T}]{|}[S^{\prime},% \omega_{S}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = [ caligraphic_A [ italic_T start_POSTSUBSCRIPT italic_k italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ], and j{1,,m}𝑗1𝑚\exists j\in\{1,\ldots,m\}∃ italic_j ∈ { 1 , … , italic_m } s.t. P2[Tji,ωT]|[S,ωS]superscriptsuperscriptabsentsubscript𝑃2conditionalsubscript𝑇𝑗𝑖superscriptsubscript𝜔𝑇superscript𝑆subscript𝜔𝑆P_{2}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[T_{ji},\omega_{T}^{\prime}]{% |}[S^{\prime},\omega_{S}]italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUBSCRIPT italic_j italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] and ωT=a1awωTsubscript𝜔𝑇subscript𝑎1subscript𝑎𝑤superscriptsubscript𝜔𝑇\omega_{T}=a_{1}\!\cdot\!\dots\!\cdot\!a_{w}\!\cdot\!\omega_{T}^{\prime}italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT = italic_a start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋅ … ⋅ italic_a start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT ⋅ italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, where a1,,awsubscript𝑎1subscript𝑎𝑤a_{1},\dots,a_{w}italic_a start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , … , italic_a start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT are the labels in one of the paths to []jsuperscript𝑗[\,]^{j}[ ] start_POSTSUPERSCRIPT italic_j end_POSTSUPERSCRIPT in 𝒜𝒜\mathcal{A}caligraphic_A.

    For every possible transition P2P2superscriptabsentsubscript𝑃2superscriptsubscript𝑃2P_{2}\stackrel{{\scriptstyle}}{{\rightarrow}}P_{2}^{\prime}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT we have that there exist 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, W𝑊Witalic_W, Twjsubscriptsuperscript𝑇𝑤𝑗T^{\prime}_{wj}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_w italic_j end_POSTSUBSCRIPT (for every wW𝑤𝑊w\in Witalic_w ∈ italic_W, jJ𝑗𝐽j\in Jitalic_j ∈ italic_J), Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, ωTsuperscriptsubscript𝜔𝑇\omega_{T}^{\prime}italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and ωSsuperscriptsubscript𝜔𝑆\omega_{S}^{\prime}italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT s.t.
    P2=[𝒜[{lj:Twj}jJ]wW,ωT]|[S,ωS]superscriptsubscript𝑃2conditionalsuperscript𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscriptsuperscript𝑇𝑤𝑗𝑗𝐽𝑤𝑊superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆P_{2}^{\prime}=[\mathcal{A^{\prime}}[{\oplus\{{l}_{j}:{T^{\prime}_{w}}_{j}\}_{% j\in J}}]^{w\in W},\omega_{T}^{\prime}]{|}[S^{\prime},\omega_{S}^{\prime}]italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = [ caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_w ∈ italic_W end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] and
    P1i[𝒜[Twi]wW,ωT]|[S,ωSli]superscriptabsentsuperscriptsubscript𝑃1𝑖conditionalsuperscript𝒜superscriptdelimited-[]subscriptsuperscript𝑇𝑤𝑖𝑤𝑊superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆subscript𝑙𝑖P_{1}^{i}\stackrel{{\scriptstyle}}{{\rightarrow}}[\mathcal{A^{\prime}}[{T^{% \prime}_{wi}}]^{w\in W},\omega_{T}^{\prime}]{|}[S^{\prime},\omega_{S}^{\prime}% \!\cdot\!l_{i}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_w italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_w ∈ italic_W end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ].

Lemma 20.

Consider P1=[𝒜[Tk]kK,ωT]|[S,ωS]subscript𝑃1conditional𝒜superscriptdelimited-[]subscript𝑇𝑘𝑘𝐾subscript𝜔𝑇𝑆subscript𝜔𝑆P_{1}=[\mathcal{A}[{T_{k}}]^{k\in K},\omega_{T}]{|}[S,\omega_{S}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT = [ caligraphic_A [ italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] and P2=[Tj,ωT]|[S,ωS]subscript𝑃2conditionalsubscript𝑇𝑗superscriptsubscript𝜔𝑇𝑆subscript𝜔𝑆P_{2}=[T_{j},\omega_{T}^{\prime}]{|}[S,\omega_{S}]italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT = [ italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] with ωT=a1awωTsubscript𝜔𝑇subscript𝑎1subscript𝑎𝑤superscriptsubscript𝜔𝑇\omega_{T}=a_{1}\!\cdot\!\dots\!\cdot\!a_{w}\!\cdot\!\omega_{T}^{\prime}italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT = italic_a start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋅ … ⋅ italic_a start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT ⋅ italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, where a1,,awsubscript𝑎1subscript𝑎𝑤a_{1},\dots,a_{w}italic_a start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , … , italic_a start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT are the labels in one of the paths to []jsuperscript𝑗[\,]^{j}[ ] start_POSTSUPERSCRIPT italic_j end_POSTSUPERSCRIPT in 𝒜𝒜\mathcal{A}caligraphic_A. We have that if P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is a correct composition, then also P1subscript𝑃1P_{1}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT is a correct composition.

Proof A.7.

By contraposition, assume P1subscript𝑃1P_{1}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT is not a correct composition. This implies the existence of P1superscriptsubscript𝑃1P_{1}^{\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, from which it is not possible to reach a successful configuration, such that P1P1superscriptsuperscriptabsentsubscript𝑃1superscriptsubscript𝑃1P_{1}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P_{1}^{\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. If the labels a1,,awsubscript𝑎1subscript𝑎𝑤a_{1},\dots,a_{w}italic_a start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , … , italic_a start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT were not consumed, we extend P1P1superscriptsuperscriptabsentsubscript𝑃1superscriptsubscript𝑃1P_{1}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P_{1}^{\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT to P1P1′′superscriptsuperscriptabsentsubscript𝑃1superscriptsubscript𝑃1′′P_{1}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P_{1}^{\prime\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT by allowing the l.h.s. type to consume all the labels a1,,awsubscript𝑎1subscript𝑎𝑤a_{1},\dots,a_{w}italic_a start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , … , italic_a start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT. We have that also from P1′′superscriptsubscript𝑃1′′P_{1}^{\prime\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is not possible to reach a successful configuration. We now reorder the transitions in P1P1′′superscriptsuperscriptabsentsubscript𝑃1superscriptsubscript𝑃1′′P_{1}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P_{1}^{\prime\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that in the initial w𝑤witalic_w steps the l.h.s. type consumes the labels a1,,awsubscript𝑎1subscript𝑎𝑤a_{1},\dots,a_{w}italic_a start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , … , italic_a start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT. After these transitions the configuration P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is reached. This implies that also P2P1′′superscriptsuperscriptabsentsubscript𝑃2superscriptsubscript𝑃1′′P_{2}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P_{1}^{\prime\prime}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, but this is not possible because P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is a correct composition and from P1′′superscriptsubscript𝑃1′′P_{1}^{\prime\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT no successful configuration can be reached.

Lemma 21.

Consider the session type T=𝒜[{lj:Tkj}jJ]kK𝑇𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscript𝑇𝑘𝑗𝑗𝐽𝑘𝐾T=\mathcal{A}[{\oplus\{{l}_{j}:{T_{k}}_{j}\}_{j\in J}}]^{k\in K}italic_T = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT. Let P2=[T,ωT]|[S,ωS]subscript𝑃2conditional𝑇subscript𝜔𝑇𝑆subscript𝜔𝑆P_{2}=[T,\omega_{T}]|[S,\omega_{S}]italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT = [ italic_T , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] and P1i=[𝒜[Tki]kK,ωT]|[S,ωSli]superscriptsubscript𝑃1𝑖conditional𝒜superscriptdelimited-[]subscript𝑇𝑘𝑖𝑘𝐾subscript𝜔𝑇𝑆subscript𝜔𝑆subscript𝑙𝑖P_{1}^{i}=[\mathcal{A}[{T_{ki}}]^{k\in K},\omega_{T}]|[S,\omega_{S}\!\cdot\!l_% {i}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT = [ caligraphic_A [ italic_T start_POSTSUBSCRIPT italic_k italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ], for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J. If P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is a correct composition then, for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J, there exists [T,ωT]|[S,ωS]conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}][ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] such that P1i[T,ωT]|[S,ωS]superscriptsuperscriptsubscript𝑃1𝑖conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆P_{1}^{i}\rightarrow^{*}[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S% }^{\prime}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT → start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] and [T,ωT]|[S,ωS]conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆square-root[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}]\surd[ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] √.

Proof A.8.

Given that P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is a correct composition, we know that there exists [T,ωT]|[S,ωS]conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}][ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] s.t. [𝒜[{lj:Tkj}jJ]kK,ωT]|[S,ωS][T,ωT]|[S,ωS]superscriptconditional𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscript𝑇𝑘𝑗𝑗𝐽𝑘𝐾subscript𝜔𝑇𝑆subscript𝜔𝑆conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆[\mathcal{A}[{\oplus\{{l}_{j}:{T_{k}}_{j}\}_{j\in J}}]^{k\in K},\omega_{T}]|[S% ,\omega_{S}]\rightarrow^{*}[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega% _{S}^{\prime}][ caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] → start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] and [T,ωT]|[S,ωS]conditionalsuperscript𝑇superscriptsubscript𝜔𝑇superscript𝑆superscriptsubscript𝜔𝑆square-root[T^{\prime},\omega_{T}^{\prime}]|[S^{\prime},\omega_{S}^{\prime}]\surd[ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] √. During this sequence of transitions, the input context 𝒜𝒜\mathcal{A}caligraphic_A will become without input branchings, because a configuration that contains one type with an input branching is not successful. In other terms there exist a prefix of the sequence of transitions, at the end of which the input context becomes without input branchings. We proceed by induction on the length of such a prefix. If the length is zero, we can apply the first item of Lemma 19 to conclude that P2P1isuperscriptabsentsubscript𝑃2superscriptsubscript𝑃1𝑖P_{2}\stackrel{{\scriptstyle}}{{\rightarrow}}P_{1}^{i}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT, for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J, hence also P1isuperscriptsubscript𝑃1𝑖P_{1}^{i}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT can reach a successful configuration. In the inductive step, we consider the first transition of P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT, we apply the last item of Lemma 19 to show that also P1isuperscriptsubscript𝑃1𝑖P_{1}^{i}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT, for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J, can perform a transition such that it is possible to apply again the hypothesis on the reached configurations. This is possible because if P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is correct, also the configurations it can reach are correct.

Proposition 22.

Consider the session type T=𝒜[{lj:Tkj}jJ]kK𝑇𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscript𝑇𝑘𝑗𝑗𝐽𝑘𝐾T=\mathcal{A}[{\oplus\{{l}_{j}:{T_{k}}_{j}\}_{j\in J}}]^{k\in K}italic_T = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT. If [T,ωT]|[S,ωS]conditional𝑇subscript𝜔𝑇𝑆subscript𝜔𝑆[T,\omega_{T}]|[S,\omega_{S}][ italic_T , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] is a correct composition then, for every iJ𝑖𝐽i\in Jitalic_i ∈ italic_J, we have that also [𝒜[Tki]kK,ωT]|[S,ωSli]conditional𝒜superscriptdelimited-[]subscript𝑇𝑘𝑖𝑘𝐾subscript𝜔𝑇𝑆subscript𝜔𝑆subscript𝑙𝑖[\mathcal{A}[{T_{ki}}]^{k\in K},\omega_{T}]|[S,\omega_{S}\!\cdot\!l_{i}][ caligraphic_A [ italic_T start_POSTSUBSCRIPT italic_k italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ] is a correct composition.

Proof A.9.

By contraposition, assume iJ𝑖𝐽i\in Jitalic_i ∈ italic_J s.t. P1i=[𝒜[Tki]kK,ωT]|[S,ωSli]superscriptsubscript𝑃1𝑖conditional𝒜superscriptdelimited-[]subscript𝑇𝑘𝑖𝑘𝐾subscript𝜔𝑇𝑆subscript𝜔𝑆subscript𝑙𝑖P_{1}^{i}=[\mathcal{A}[{T_{ki}}]^{k\in K},\omega_{T}]|[S,\omega_{S}\!\cdot\!l_% {i}]italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT = [ caligraphic_A [ italic_T start_POSTSUBSCRIPT italic_k italic_i end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT ] | [ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ] is not a correct composition. This means the existence of P1iPsuperscriptsuperscriptabsentsuperscriptsubscript𝑃1𝑖superscript𝑃P_{1}^{i}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P^{\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that Psuperscript𝑃P^{\prime}italic_P start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT cannot reach a successful configuration. By induction on the length of this sequence of transition we show that, differently from what assumed, Psuperscript𝑃P^{\prime}italic_P start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT can reach a successful configuration. If the length is 0, we simply apply Lemma 21 to show that P1i=Psuperscriptsubscript𝑃1𝑖superscript𝑃P_{1}^{i}=P^{\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT = italic_P start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT can reach a successful configuration. If the length is not 0, we consider two possible cases: (i) the initial transition of P1iP′′superscriptabsentsuperscriptsubscript𝑃1𝑖superscript𝑃′′P_{1}^{i}\stackrel{{\scriptstyle}}{{\rightarrow}}P^{\prime\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP italic_P start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT of P1iPsuperscriptsuperscriptabsentsuperscriptsubscript𝑃1𝑖superscript𝑃P_{1}^{i}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P^{\prime}italic_P start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_i end_POSTSUPERSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT consumes the label lisubscript𝑙𝑖l_{i}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT from the the queue of the r.h.s. type or (ii) it does not. In case (i) we use the corresponding item 2 in Lemma 19 to see that we can apply Lemma 20 on P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT and P′′superscript𝑃′′P^{\prime\prime}italic_P start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, in order to conclude that P′′superscript𝑃′′P^{\prime\prime}italic_P start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is a correct composition. Given that P′′Psuperscriptsuperscriptabsentsuperscript𝑃′′superscript𝑃P^{\prime\prime}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P^{\prime}italic_P start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT we can conclude that P′′superscript𝑃′′P^{\prime\prime}italic_P start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT can reach a successful configuration. In case (ii) we use the corresponding item 1 in Lemma 19 to conclude that we can apply again the inductive hypothesis on the shortest sequence of transitions P′′Psuperscriptsuperscriptabsentsuperscript𝑃′′superscript𝑃P^{\prime\prime}\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}P^{\prime}italic_P start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT italic_P start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. This is possible because P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT has a corresponding transition to P2P2superscriptabsentsubscript𝑃2superscriptsubscript𝑃2P_{2}\stackrel{{\scriptstyle}}{{\rightarrow}}P_{2}^{\prime}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, such that P′′superscript𝑃′′P^{\prime\prime}italic_P start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT and P2superscriptsubscript𝑃2P_{2}^{\prime}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT still satisfies the assumption in the statement of the Lemma. In particular P2superscriptsubscript𝑃2P_{2}^{\prime}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is a correct composition because also P2subscript𝑃2P_{2}italic_P start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT is a correct composition.

Lemma 23.

If [S,ωS]|[R,ωR]conditional𝑆subscript𝜔𝑆𝑅subscript𝜔𝑅[S,\omega_{S}]|[R,\omega_{R}][ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition then S𝑆Sitalic_S is controllable.

Proof A.10.

We show the existence of a type T𝑇Titalic_T such that [S,ϵ]|[T,ϵ]conditional𝑆italic-ϵ𝑇italic-ϵ[S,\epsilon]|[T,\epsilon][ italic_S , italic_ϵ ] | [ italic_T , italic_ϵ ] is a correct composition.

Consider a type T𝑇Titalic_T defined as follows. Assume ωS=l1SlkSsubscript𝜔𝑆superscriptsubscript𝑙1𝑆superscriptsubscript𝑙𝑘𝑆\omega_{S}=l_{1}^{S}\cdots l_{k}^{S}italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT = italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_S end_POSTSUPERSCRIPT ⋯ italic_l start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_S end_POSTSUPERSCRIPT and ωR=l1lwRsubscript𝜔𝑅subscript𝑙1superscriptsubscript𝑙𝑤𝑅\omega_{R}=l_{1}\cdots l_{w}^{R}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT = italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_l start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_R end_POSTSUPERSCRIPT. The type T𝑇Titalic_T initially performs k𝑘kitalic_k outputs with single output labels l1subscript𝑙1l_{1}italic_l start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT, \cdots, lksubscript𝑙𝑘l_{k}italic_l start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT, respectively. After such outputs, it becomes like R𝑅Ritalic_R, with the difference that along all of its paths, the initial w𝑤witalic_w input branchings are replaced by one of its continuation as follows: the i𝑖iitalic_i-th input branching is replaced by its continuation in the branch labeled with liRsuperscriptsubscript𝑙𝑖𝑅l_{i}^{R}italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_R end_POSTSUPERSCRIPT.

We now show by contraposition that [S,ϵ]|[T,ϵ]conditional𝑆italic-ϵ𝑇italic-ϵ[S,\epsilon]|[T,\epsilon][ italic_S , italic_ϵ ] | [ italic_T , italic_ϵ ] is a correct composition. If [S,ϵ]|[T,ϵ]conditional𝑆italic-ϵ𝑇italic-ϵ[S,\epsilon]|[T,\epsilon][ italic_S , italic_ϵ ] | [ italic_T , italic_ϵ ] is not correct, then there exists [S,ϵ]|[T,ϵ][S,ωS]|[T,ωT]superscriptsuperscriptabsentconditional𝑆italic-ϵ𝑇italic-ϵconditionalsuperscript𝑆superscriptsubscript𝜔𝑆superscript𝑇superscriptsubscript𝜔𝑇[S,\epsilon]|[T,\epsilon]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[S^{% \prime},\omega_{S}^{\prime}]|[T^{\prime},\omega_{T}^{\prime}][ italic_S , italic_ϵ ] | [ italic_T , italic_ϵ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] such that from [S,ωS]|[T,ωT]conditionalsuperscript𝑆superscriptsubscript𝜔𝑆superscript𝑇superscriptsubscript𝜔𝑇[S^{\prime},\omega_{S}^{\prime}]|[T^{\prime},\omega_{T}^{\prime}][ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] it is not possible to reach a successful configuration. It is not restrictive to assume that during [S,ϵ]|[T,ϵ][S,ωS]|[T,ωT]superscriptsuperscriptabsentconditional𝑆italic-ϵ𝑇italic-ϵconditionalsuperscript𝑆superscriptsubscript𝜔𝑆superscript𝑇superscriptsubscript𝜔𝑇[S,\epsilon]|[T,\epsilon]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[S^{% \prime},\omega_{S}^{\prime}]|[T^{\prime},\omega_{T}^{\prime}][ italic_S , italic_ϵ ] | [ italic_T , italic_ϵ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] the r.h.s. type has produced the queue ωSsubscript𝜔𝑆\omega_{S}italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT (in fact, if it has not produced them, we continue the computation performing them). We can also assume that outputs in T𝑇Titalic_T, corresponding to outputs in R𝑅Ritalic_R along an initial path with less than w𝑤witalic_w inputs have been all performed (also in this case, if these outputs were not performed, we continue the computation executing them). We have that also [S,ωS]|[R,ωR]conditional𝑆subscript𝜔𝑆𝑅subscript𝜔𝑅[S,\omega_{S}]|[R,\omega_{R}][ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] can perform a computation [S,ωS]|[R,ωR][S,ωS]|[T,ωT]superscriptsuperscriptabsentconditional𝑆subscript𝜔𝑆𝑅subscript𝜔𝑅conditionalsuperscript𝑆superscriptsubscript𝜔𝑆superscript𝑇superscriptsubscript𝜔𝑇[S,\omega_{S}]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[S^{% \prime},\omega_{S}^{\prime}]|[T^{\prime},\omega_{T}^{\prime}][ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ]. Given that [S,ωS]|[R,ωR]conditional𝑆subscript𝜔𝑆𝑅subscript𝜔𝑅[S,\omega_{S}]|[R,\omega_{R}][ italic_S , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition, we have that from [S,ωS]|[T,ωT]conditionalsuperscript𝑆superscriptsubscript𝜔𝑆superscript𝑇superscriptsubscript𝜔𝑇[S^{\prime},\omega_{S}^{\prime}]|[T^{\prime},\omega_{T}^{\prime}][ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_S end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] will be possible to reach a successful configuration, thus contradicting the above assumption.

See 8

Proof A.11.

Given that [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition, there exist Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, ω′′superscript𝜔′′\omega^{\prime\prime}italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, R′′superscript𝑅′′R^{\prime\prime}italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, and ωR′′superscriptsubscript𝜔𝑅′′\omega_{R}^{\prime\prime}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that [S,ω]|[R,ωR][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[S^{% \prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] and [S,ω]|[R′′,ωR′′]conditionalsuperscript𝑆superscript𝜔superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[S^{\prime},\omega^{\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}]\surd[ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √. We proceed by induction on the length of this sequence of transition.

If the length is 0, then [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅square-root[S,\omega]|[R,\omega_{R}]\surd[ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] √, that implies 𝗎𝗇𝖿𝗈𝗅𝖽(S)=𝐞𝐧𝐝𝗎𝗇𝖿𝗈𝗅𝖽𝑆𝐞𝐧𝐝\mathsf{unfold}(S)=\mathbf{end}sansserif_unfold ( italic_S ) = bold_end, that also implies 𝗎𝗇𝖿𝗈𝗅𝖽(T)=𝐞𝐧𝐝𝗎𝗇𝖿𝗈𝗅𝖽𝑇𝐞𝐧𝐝\mathsf{unfold}(T)=\mathbf{end}sansserif_unfold ( italic_T ) = bold_end (because TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S), from which we have [T,ω]|[R,ωR]conditional𝑇𝜔𝑅subscript𝜔𝑅square-root[T,\omega]|[R,\omega_{R}]\surd[ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] √.

If the length is greater than 0, we proceed by case analysis on the possible first transition [S,ω]|[R,ωR][S′′,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑆′′superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[S^{\prime% \prime},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{% \prime\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ].

If the transition is inferred by R𝑅Ritalic_R it is sufficient to observe that S′′=Ssuperscript𝑆′′𝑆S^{\prime\prime}=Sitalic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT = italic_S and [T,ω]|[R,ωR][T,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditional𝑇superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T,\omega^{% \prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ], and then apply the inductive hypothesis because [S′′,ω′′′]|[R′′′,ωR′′′]conditionalsuperscript𝑆′′superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S^{\prime\prime},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_% {R}^{\prime\prime\prime}][ italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] is a correct composition in that it is reachable from a correct composition.

We now consider that the transition is inferred by S𝑆Sitalic_S.
We first discuss the case in which 𝗎𝗇𝖿𝗈𝗅𝖽(S)={li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼\mathsf{unfold}(S)=\oplus\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT. In this case, the above transition is [S,ω]|[R,ωR][Si,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑆𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[S_{i},\omega% ^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ], for some iI𝑖𝐼i\in Iitalic_i ∈ italic_I. Given that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, and S𝑆Sitalic_S is controllable by Lemma 23, we have 𝗎𝗇𝖿𝗈𝗅𝖽(T)={li:Ti}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑖subscript𝑇𝑖𝑖𝐼\mathsf{unfold}(T)=\oplus\{{l}_{i}:{T}_{i}\}_{i\in I}sansserif_unfold ( italic_T ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT with TiSisubscript𝑇𝑖subscript𝑆𝑖T_{i}\operatorname{\leq}S_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT, for every iI𝑖𝐼i\in Iitalic_i ∈ italic_I. This ensures that [T,ω]|[R,ωR][Ti,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑇𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T_{i},\omega% ^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ]. Then we can apply the inductive hypothesis because TiSisubscript𝑇𝑖subscript𝑆𝑖T_{i}\operatorname{\leq}S_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT and [Si,ω′′′]|[R′′′,ωR′′′]conditionalsubscript𝑆𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S_{i},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime% \prime\prime}][ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] is a correct composition.

We now discuss the case in which 𝗎𝗇𝖿𝗈𝗅𝖽(S)=&{li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆subscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼\mathsf{unfold}(S)=\&\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT. There are two possible subcases: (i) also T𝑇Titalic_T starts with an input branching, i.e., 𝗎𝗇𝖿𝗈𝗅𝖽(T)=&{lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇subscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\&\{l_{j}:T_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = & { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT, or (ii) T𝑇Titalic_T starts with an output selection, i.e., 𝗎𝗇𝖿𝗈𝗅𝖽(T)={lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\oplus\{l_{j}:T_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT.

In case (i), the above transition is [S,ω]|[R,ωR][Si,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑆𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[S_{i},\omega% ^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ], for some iI𝑖𝐼i\in Iitalic_i ∈ italic_I. Given that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, and S𝑆Sitalic_S is controllable by Lemma 23, we have 𝗎𝗇𝖿𝗈𝗅𝖽(T)=&{lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇subscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\&\{{l}_{j}:{T}_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = & { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT, JK𝐾𝐽J\supseteq Kitalic_J ⊇ italic_K, and kK.TkSkfor-all𝑘.𝐾subscript𝑇𝑘subscript𝑆𝑘\forall k\in K\ldotp T_{k}\operatorname{\leq}S_{k}∀ italic_k ∈ italic_K . italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT, where K={kI|Sk is controllable}𝐾conditional-set𝑘𝐼subscript𝑆𝑘 is controllableK=\{k\in I\;|\;S_{k}\text{ is controllable}\}italic_K = { italic_k ∈ italic_I | italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT is controllable }. Given that [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition and [S,ω]|[R,ωR][Si,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑆𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[S_{i},\omega% ^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ], also the latter configuration is a correct composition. By Lemma 23 we have that Sisubscript𝑆𝑖S_{i}italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT is controllable. This implies that iK𝑖𝐾i\in Kitalic_i ∈ italic_K, hence also iJ𝑖𝐽i\in Jitalic_i ∈ italic_J. This ensures that [T,ω]|[R,ωR][Ti,ω′′′]|[R′′′,ωR′′′]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑇𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T_{i},\omega% ^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime\prime\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ]. Then we can apply the inductive hypothesis because TiSisubscript𝑇𝑖subscript𝑆𝑖T_{i}\operatorname{\leq}S_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT and [Si,ω′′′]|[R′′′,ωR′′′]conditionalsubscript𝑆𝑖superscript𝜔′′′superscript𝑅′′′superscriptsubscript𝜔𝑅′′′[S_{i},\omega^{\prime\prime\prime}]|[R^{\prime\prime\prime},\omega_{R}^{\prime% \prime\prime}][ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ] is a correct composition.

In case (ii), given that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, and S𝑆Sitalic_S is controllable, we have that 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(S)=𝒜[{li:Ski}iJ]kK𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑆𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑖subscriptsubscript𝑆𝑘𝑖𝑖𝐽𝑘𝐾\mathsf{selUnfold}(S)=\mathcal{A}[{\oplus\{{l}_{i}:{S_{k}}_{i}\}_{i\in J}}]^{k% \in K}sansserif_selUnfold ( italic_S ) = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_J end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT, and 𝗎𝗇𝖿𝗈𝗅𝖽(T)={lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇direct-sumsubscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\oplus\{l_{j}:T_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT with Tj𝒜[Skj]kKsubscript𝑇𝑗𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾T_{j}\operatorname{\leq}\mathcal{A}[{S_{kj}}]^{k\in K}italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ≤ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT, for every jJ𝑗𝐽j\in Jitalic_j ∈ italic_J. We first observe that the sequence of transitions [S,ω]|[R,ωR][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝑆𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[S,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[S^{% \prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ], with [S,ω′′]|[R′′,ωR′′]conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[S^{\prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}]\surd[ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √, includes at least one output selection ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT executed by one of the output selections filling the holes in 𝒜𝒜\mathcal{A}caligraphic_A. This label ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT is the first one emitted by the l.h.s. type after it has executed input branchings in 𝒜𝒜\mathcal{A}caligraphic_A. We have that the same sequence of transitions, excluding the output of ljsubscript𝑙𝑗l_{j}italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT, can be executed from the configuration [𝒜[Skj]kK,ω]|[R,ωRlj]conditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ]. Such a sequence is [𝒜[Skj]kK,ω]|[R,ωRlj][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}]\stackrel{% {\scriptstyle}}{{\rightarrow}}^{*}[S^{\prime},\omega^{\prime\prime}]|[R^{% \prime\prime},\omega_{R}^{\prime\prime}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ], with [S,ω′′]|[R′′,ωR′′]conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[S^{\prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime\prime}]\surd[ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √; notice that it is shorter than the above one. We now consider [T,ω]|[R,ωR][Ti,ω]|[R,ωRlj]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsubscript𝑇𝑖𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T_{i},\omega% ]|[R,\omega_{R}\!\cdot\!{l_{j}}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ]. We can now apply the inductive hypothesis on the shorter sequence [𝒜[Skj]kK,ω]|[R,ωRlj][S,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗conditionalsuperscript𝑆superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}]\stackrel{% {\scriptstyle}}{{\rightarrow}}^{*}[S^{\prime},\omega^{\prime\prime}]|[R^{% \prime\prime},\omega_{R}^{\prime\prime}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ], because Tj𝒜[Skj]kKsubscript𝑇𝑗𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾T_{j}\operatorname{\leq}\mathcal{A}[{S_{kj}}]^{k\in K}italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ≤ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT and by Proposition 22 [𝒜[Skj]kK,ω]|[R,ωRlj]conditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑗𝑘𝐾𝜔𝑅subscript𝜔𝑅subscript𝑙𝑗[\mathcal{A}[{S_{kj}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l_{j}][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_j end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ] is a correct composition.

See 9

Proof A.12.

If S𝑆Sitalic_S is not controllable, then the thesis trivially holds because TSsquare-image-of-or-equals𝑇𝑆T\sqsubseteq Sitalic_T ⊑ italic_S for every T𝑇Titalic_T.

We now consider S𝑆Sitalic_S controllable, and we prove the thesis by showing that if TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S then, for every ω𝜔\omegaitalic_ω, R𝑅Ritalic_R, and ωRsubscript𝜔𝑅\omega_{R}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT such that [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition, we have that the following holds:

  • if [T,ω]|[R,ωR][T,ω]|[R,ωR]conditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[T,\omega]|[R,\omega_{R}]\rightarrow[T^{\prime},\omega^{\prime}]|[R^{\prime},% \omega_{R}^{\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] → [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] then there exists Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and [S,ω]|[R,ωR]conditionalsuperscript𝑆superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[S^{\prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] is a correct composition.

The above implies the thesis because, given TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S and the correct composition [S,ϵ]|[R,ϵ]conditional𝑆italic-ϵ𝑅italic-ϵ[S,\epsilon]|[R,\epsilon][ italic_S , italic_ϵ ] | [ italic_R , italic_ϵ ], if there exists a computation [T,ϵ]|[R,ϵ][T,ω]|[R,ωR]superscriptsuperscriptabsentconditional𝑇italic-ϵ𝑅italic-ϵconditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[T,\epsilon]|[R,\epsilon]\stackrel{{\scriptstyle}}{{\rightarrow}}^{*}[T^{% \prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_T , italic_ϵ ] | [ italic_R , italic_ϵ ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ], we can apply the above result on each step of the computation to prove that there exists Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT such that TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and [S,ω]|[R,ωR]conditionalsuperscript𝑆superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[S^{\prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] is a correct composition. Then, by Proposition 8, we have that there exist T′′superscript𝑇′′T^{\prime\prime}italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, ω′′superscript𝜔′′\omega^{\prime\prime}italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, R′′superscript𝑅′′R^{\prime\prime}italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT, and ωR′′superscriptsubscript𝜔𝑅′′\omega_{R}^{\prime\prime}italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT such that [T,ω]|[R,ωR][T′′,ω′′]|[R′′,ωR′′]superscriptsuperscriptabsentconditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅conditionalsuperscript𝑇′′superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′[T^{\prime},\omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}]\stackrel{{% \scriptstyle}}{{\rightarrow}}^{*}[T^{\prime\prime},\omega^{\prime\prime}]|[R^{% \prime\prime},\omega_{R}^{\prime\prime}][ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT [ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] and [T′′,ω′′]|[R′′,ωR′′]conditionalsuperscript𝑇′′superscript𝜔′′superscript𝑅′′superscriptsubscript𝜔𝑅′′square-root[T^{\prime\prime},\omega^{\prime\prime}]|[R^{\prime\prime},\omega_{R}^{\prime% \prime}]\surd[ italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ] √.

We now prove the above result. The transition [T,ω]|[R,ωR][T,ω]|[R,ωR]superscriptabsentconditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑇superscript𝜔superscript𝑅superscriptsubscript𝜔𝑅[T,\omega]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}}[T^{\prime},% \omega^{\prime}]|[R^{\prime},\omega_{R}^{\prime}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] can be of four possible kinds:

  1. (1)

    the consumption of a message from the r.h.s. queue, i.e. [T,ω]|[R,lωR][T,ω]|[R,ωR]conditional𝑇𝜔𝑅𝑙superscriptsubscript𝜔𝑅conditional𝑇𝜔superscript𝑅superscriptsubscript𝜔𝑅[T,\omega]|[R,l\!\cdot\!\omega_{R}^{\prime}]\rightarrow[T,\omega]|[R^{\prime},% \omega_{R}^{\prime}][ italic_T , italic_ω ] | [ italic_R , italic_l ⋅ italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] → [ italic_T , italic_ω ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ];

  2. (2)

    the insertion of a new message in the l.h.s. queue, i.e. [T,ω]|[R,ωR][T,ωl]|[R,ωR]conditional𝑇𝜔𝑅subscript𝜔𝑅conditional𝑇𝜔𝑙superscript𝑅subscript𝜔𝑅[T,\omega]|[R,\omega_{R}]\rightarrow[T,\omega\!\cdot\!l]|[R^{\prime},\omega_{R}][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] → [ italic_T , italic_ω ⋅ italic_l ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ];

  3. (3)

    the consumption of a message from the l.h.s. queue, i.e. [T,lq]|[R,ωR][T,ω]|[R,ωR]conditional𝑇𝑙superscript𝑞𝑅subscript𝜔𝑅conditionalsuperscript𝑇superscript𝜔𝑅subscript𝜔𝑅[T,l\!\cdot\!q^{\prime}]|[R,\omega_{R}]\rightarrow[T^{\prime},\omega^{\prime}]% |[R,\omega_{R}][ italic_T , italic_l ⋅ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] → [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ];

  4. (4)

    the insertion of a new message in the r.h.s. queue, i.e. [T,ω]|[R,ωR][T,ω]|[R,ωRl]conditional𝑇𝜔𝑅subscript𝜔𝑅conditionalsuperscript𝑇𝜔𝑅subscript𝜔𝑅𝑙[T,\omega]|[R,\omega_{R}]\rightarrow[T^{\prime},\omega]|[R,\omega_{R}\!\cdot\!l][ italic_T , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] → [ italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l ].

In the first two cases, we simply observe that there exists also [S,ω]|[R,lωR][S,ω]|[R,ωR]conditional𝑆𝜔𝑅𝑙superscriptsubscript𝜔𝑅conditional𝑆𝜔superscript𝑅superscriptsubscript𝜔𝑅[S,\omega]|[R,l\!\cdot\!\omega_{R}^{\prime}]\rightarrow[S,\omega]|[R^{\prime},% \omega_{R}^{\prime}][ italic_S , italic_ω ] | [ italic_R , italic_l ⋅ italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] → [ italic_S , italic_ω ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] (resp. [S,ω]|[R,ωR][S,ωl]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅conditional𝑆𝜔𝑙superscript𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}]\rightarrow[S,\omega\!\cdot\!l]|[R^{\prime},\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] → [ italic_S , italic_ω ⋅ italic_l ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ]), that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, and also [S,ω]|[R,ωR]conditional𝑆𝜔superscript𝑅superscriptsubscript𝜔𝑅[S,\omega]|[R^{\prime},\omega_{R}^{\prime}][ italic_S , italic_ω ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] (resp. [S,ωl]|[R,ωR]conditional𝑆𝜔𝑙superscript𝑅subscript𝜔𝑅[S,\omega\!\cdot\!l]|[R^{\prime},\omega_{R}][ italic_S , italic_ω ⋅ italic_l ] | [ italic_R start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ]) is a correct composition because reachable from the correct composition [S,ω]|[R,lωR]conditional𝑆𝜔𝑅𝑙superscriptsubscript𝜔𝑅[S,\omega]|[R,l\!\cdot\!\omega_{R}^{\prime}][ italic_S , italic_ω ] | [ italic_R , italic_l ⋅ italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] (resp. [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ]).

In the third case we have that 𝗎𝗇𝖿𝗈𝗅𝖽(T)𝗎𝗇𝖿𝗈𝗅𝖽𝑇\mathsf{unfold}(T)sansserif_unfold ( italic_T ) starts with an input branching. Given that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, and S𝑆Sitalic_S is controllable, also 𝗎𝗇𝖿𝗈𝗅𝖽(S)𝗎𝗇𝖿𝗈𝗅𝖽𝑆\mathsf{unfold}(S)sansserif_unfold ( italic_S ) must start with an input branching, i.e. 𝗎𝗇𝖿𝗈𝗅𝖽(S)=&{li:Si}iI𝗎𝗇𝖿𝗈𝗅𝖽𝑆subscriptconditional-setsubscript𝑙𝑖subscript𝑆𝑖𝑖𝐼\mathsf{unfold}(S)=\&\{{l}_{i}:{S}_{i}\}_{i\in I}sansserif_unfold ( italic_S ) = & { italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_i ∈ italic_I end_POSTSUBSCRIPT. By definition of \operatorname{\leq} we have that 𝗎𝗇𝖿𝗈𝗅𝖽(T)=&{lj:Tj}jJ𝗎𝗇𝖿𝗈𝗅𝖽𝑇subscriptconditional-setsubscript𝑙𝑗subscript𝑇𝑗𝑗𝐽\mathsf{unfold}(T)=\&\{{l}_{j}:{T}_{j}\}_{j\in J}sansserif_unfold ( italic_T ) = & { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_J end_POSTSUBSCRIPT, JK𝐾𝐽J\supseteq Kitalic_J ⊇ italic_K, and kK.TkSkfor-all𝑘.𝐾subscript𝑇𝑘subscript𝑆𝑘\forall k\in K\ldotp T_{k}\operatorname{\leq}S_{k}∀ italic_k ∈ italic_K . italic_T start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT, where K={kI|Sk is controllable}𝐾conditional-set𝑘𝐼subscript𝑆𝑘 is controllableK=\{k\in I\;|\;S_{k}\text{ is controllable}\}italic_K = { italic_k ∈ italic_I | italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT is controllable }. Given that [S,lq]|[R,ωR]conditional𝑆𝑙superscript𝑞𝑅subscript𝜔𝑅[S,l\!\cdot\!q^{\prime}]|[R,\omega_{R}][ italic_S , italic_l ⋅ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition, there exists iI𝑖𝐼i\in Iitalic_i ∈ italic_I s.t. l=li𝑙subscript𝑙𝑖l=l_{i}italic_l = italic_l start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT and [S,lq]|[R,ωR][Si,ω]|[R,ωR]superscriptabsentconditional𝑆𝑙superscript𝑞𝑅subscript𝜔𝑅conditionalsubscript𝑆𝑖superscript𝜔𝑅subscript𝜔𝑅[S,l\!\cdot\!q^{\prime}]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}% }[S_{i},\omega^{\prime}]|[R,\omega_{R}][ italic_S , italic_l ⋅ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ]. The former configuration is a correct composition, hence also the latter is such. This implies, by Lemma 23, that Sisubscript𝑆𝑖S_{i}italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT is controllable, hence iK𝑖𝐾i\in Kitalic_i ∈ italic_K and also iJ𝑖𝐽i\in Jitalic_i ∈ italic_J. Thus, we have [T,lq]|[R,ωR][Ti,ω]|[R,ωR]superscriptabsentconditional𝑇𝑙superscript𝑞𝑅subscript𝜔𝑅conditionalsubscript𝑇𝑖superscript𝜔𝑅subscript𝜔𝑅[T,l\!\cdot\!q^{\prime}]|[R,\omega_{R}]\stackrel{{\scriptstyle}}{{\rightarrow}% }[T_{i},\omega^{\prime}]|[R,\omega_{R}][ italic_T , italic_l ⋅ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] start_RELOP SUPERSCRIPTOP start_ARG → end_ARG start_ARG end_ARG end_RELOP [ italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ], with TiSisubscript𝑇𝑖subscript𝑆𝑖T_{i}\operatorname{\leq}S_{i}italic_T start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT. We conclude this case by observing again that [Si,ω]|[R,ωR]conditionalsubscript𝑆𝑖superscript𝜔𝑅subscript𝜔𝑅[S_{i},\omega^{\prime}]|[R,\omega_{R}][ italic_S start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT , italic_ω start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition in that reachable from the correct composition [S,lq]|[R,ωR]conditional𝑆𝑙superscript𝑞𝑅subscript𝜔𝑅[S,l\!\cdot\!q^{\prime}]|[R,\omega_{R}][ italic_S , italic_l ⋅ italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ].

In the fourth and last case, we have that 𝗎𝗇𝖿𝗈𝗅𝖽(T)𝗎𝗇𝖿𝗈𝗅𝖽𝑇\mathsf{unfold}(T)sansserif_unfold ( italic_T ) starts with an output selection, and Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is the continuation in the branch with label l𝑙litalic_l. Given that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, and S𝑆Sitalic_S is controllable, we have 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(S)=𝒜[{lj:Skj}jI]kK𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑆𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscript𝑆𝑘𝑗𝑗𝐼𝑘𝐾\mathsf{selUnfold}(S)=\mathcal{A}[{\oplus\{{l}_{j}:{S_{k}}_{j}\}_{j\in I}}]^{k% \in K}sansserif_selUnfold ( italic_S ) = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_I end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT, and TSkmsuperscript𝑇subscript𝑆𝑘𝑚T^{\prime}\operatorname{\leq}S_{km}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUBSCRIPT italic_k italic_m end_POSTSUBSCRIPT, for every kK𝑘𝐾k\in Kitalic_k ∈ italic_K and some mI𝑚𝐼m\in Iitalic_m ∈ italic_I such that lm=lsubscript𝑙𝑚𝑙l_{m}=litalic_l start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT = italic_l. It remains to show that [𝒜[Skm]kK,ω]|[R,ωRl]conditional𝒜superscriptdelimited-[]subscript𝑆𝑘𝑚𝑘𝐾𝜔𝑅subscript𝜔𝑅𝑙[\mathcal{A}[{{S_{km}}}]^{k\in K},\omega]|[R,\omega_{R}\!\cdot\!l][ caligraphic_A [ italic_S start_POSTSUBSCRIPT italic_k italic_m end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ⋅ italic_l ] is a correct composition, but this follows from Proposition 22 and the fact that [𝒜[{lj:Skj}jI]kK,ω]|[R,ωR]conditional𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscript𝑆𝑘𝑗𝑗𝐼𝑘𝐾𝜔𝑅subscript𝜔𝑅[\mathcal{A}[{\oplus\{{l}_{j}:{S_{k}}_{j}\}_{j\in I}}]^{k\in K},\omega]|[R,% \omega_{R}][ caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_I end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ], with l=lm𝑙subscript𝑙𝑚l=l_{m}italic_l = italic_l start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT for some mI𝑚𝐼m\in Iitalic_m ∈ italic_I, is a correct composition. In fact 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽(S)=𝒜[{lj:Skj}jI]kK𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽𝑆𝒜superscriptdelimited-[]direct-sumsubscriptconditional-setsubscript𝑙𝑗subscriptsubscript𝑆𝑘𝑗𝑗𝐼𝑘𝐾\mathsf{selUnfold}(S)=\mathcal{A}[{\oplus\{{l}_{j}:{S_{k}}_{j}\}_{j\in I}}]^{k% \in K}sansserif_selUnfold ( italic_S ) = caligraphic_A [ ⊕ { italic_l start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT : italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT } start_POSTSUBSCRIPT italic_j ∈ italic_I end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT and [S,ω]|[R,ωR]conditional𝑆𝜔𝑅subscript𝜔𝑅[S,\omega]|[R,\omega_{R}][ italic_S , italic_ω ] | [ italic_R , italic_ω start_POSTSUBSCRIPT italic_R end_POSTSUBSCRIPT ] is a correct composition.

A.4. Undecidability of Fair Asynchronous Subtyping

See 10

Proof A.13.

We first consider the only-if part, proving the contrapositive statement, that is, if the queue machine M𝑀Mitalic_M terminates then TS𝑇𝑆T\not\!\!\!\operatorname{\leq}Sitalic_T not ≤ italic_S. If the queue machine terminates, we have that (s,$)M(q,ϵ)superscriptsubscript𝑀𝑠currency-dollarsuperscript𝑞italic-ϵ(s,\$)\rightarrow_{M}^{*}(q^{\prime},\epsilon)( italic_s , $ ) → start_POSTSUBSCRIPT italic_M end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ϵ ). Consider now the pair of types (T,S)𝑇𝑆(T,S)( italic_T , italic_S ) with T=[[[M,_,E]]]𝑇delimited-[]delimited-[]𝑀_𝐸T=[\![\![{M,\_,E}]\!]\!]italic_T = [ [ [ italic_M , _ , italic_E ] ] ] and S=[[[M,E]]]𝑆delimited-[]delimited-[]𝑀𝐸S=[\![\![{M,E}]\!]\!]italic_S = [ [ [ italic_M , italic_E ] ] ]. If, by contradiction, TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S, since S𝑆Sitalic_S is controllable (it is compliant, e.g., with its dual) we have that by Definition 3 there exists a fair asynchronous subtyping relation \mathcal{R}caligraphic_R such that (T,S)𝑇𝑆(T,S)\in\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R. We now show that, by definition of fair asynchronous subtyping relation, \mathcal{R}caligraphic_R will have to include other pairs of types (T′′,S′′)superscript𝑇′′superscript𝑆′′(T^{\prime\prime},S^{\prime\prime})( italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) corresponding with configurations (q′′,γ′′)superscript𝑞′′superscript𝛾′′(q^{\prime\prime},\gamma^{\prime\prime})( italic_q start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) reachable in the queue machine M𝑀Mitalic_M. Consider the type T𝑇Titalic_T:

μ𝐬.&{A:{{B1ABnAA}}q{s}}AΓformulae-sequence𝜇𝐬subscriptconditional-set𝐴superscriptsubscriptsubscriptsuperscript𝐵𝐴1subscriptsuperscript𝐵𝐴subscript𝑛𝐴superscript𝑞𝑠𝐴Γ\mu\mathbf{s}.\&\{{A}\!:\!{{\{\!\!\{{B^{A}_{1}\cdots B^{A}_{n_{A}}}\}\!\!\}}_{% q^{\prime}}^{\{s\}}}\}_{A\in\Gamma}italic_μ bold_s . & { italic_A : { { italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT start_POSTSUPERSCRIPT { italic_s } end_POSTSUPERSCRIPT } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT

assuming δ(s,A)=(q,B1ABnAA)𝛿𝑠𝐴superscript𝑞subscriptsuperscript𝐵𝐴1subscriptsuperscript𝐵𝐴subscript𝑛𝐴\delta(s,A)=(q^{\prime},B^{A}_{1}\cdots B^{A}_{n_{A}})italic_δ ( italic_s , italic_A ) = ( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUPERSCRIPT italic_A end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT end_POSTSUBSCRIPT ) and

{{B1Bm}}r𝒯={[[[r]]]𝒯if m=0({B1:{{B2Bm}}r𝒯}{A:V}AΓ{B1}{E:V})otherwise\begin{array}[]{l}{\{\!\!\{{B_{1}\cdots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}\!=\!% \left\{\!\!\begin{array}[]{ll}\!{[\![\![{r}]\!]\!]}^{\mathcal{T}}&\text{if }m=% 0\\ \begin{array}[]{ll}\!\!\!\!\oplus&\!\!\!\!\big{(}\big{\{}B_{1}:{\{\!\!\{{B_{2}% \ldots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}\big{\}}\cup\\ &\!\big{\{}{A:V}\big{\}}_{A\in\Gamma\setminus\{B_{1}\}}\cup\{E:V^{\prime}\}% \big{)}\end{array}&\text{otherwise}\end{array}\right.\end{array}start_ARRAY start_ROW start_CELL { { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT = { start_ARRAY start_ROW start_CELL [ [ [ italic_r ] ] ] start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT end_CELL start_CELL if italic_m = 0 end_CELL end_ROW start_ROW start_CELL start_ARRAY start_ROW start_CELL ⊕ end_CELL start_CELL ( { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : { { italic_B start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT … italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT } ∪ end_CELL end_ROW start_ROW start_CELL end_CELL start_CELL { italic_A : italic_V } start_POSTSUBSCRIPT italic_A ∈ roman_Γ ∖ { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT } end_POSTSUBSCRIPT ∪ { italic_E : italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } ) end_CELL end_ROW end_ARRAY end_CELL start_CELL otherwise end_CELL end_ROW end_ARRAY end_CELL end_ROW end_ARRAY

It starts with an input branching, with labels for each queue alphabet symbol including the initial queue symbol $currency-dollar\$$. Then it has a sequence of output selections, including the sequence of symbols to be emitted by the queue machine after having consumed $currency-dollar\$$. Consider now the type S𝑆Sitalic_S:

&{$:μ𝐭.{A:&{A:𝐭}}AΓ{E:&{E:𝐞𝐧𝐝}}}conditional-setcurrency-dollarformulae-sequence𝜇𝐭direct-sumsubscriptconditional-set𝐴conditional-set𝐴𝐭𝐴Γconditional-set𝐸conditional-set𝐸𝐞𝐧𝐝\&\{\$:\mu\mathbf{\mathbf{t}}.\oplus\{{A}:{\&\{A:\mathbf{t}\}}\}_{A\in\Gamma}% \cup\{E:\&\{E:\mathbf{end}\}\}\}& { $ : italic_μ bold_t . ⊕ { italic_A : & { italic_A : bold_t } } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : & { italic_E : bold_end } } }

It starts with an input branching with only label $currency-dollar\$$, followed by an output selection on all symbols, including label E𝐸Eitalic_E having continuation &{E:𝐞𝐧𝐝}conditional-set𝐸𝐞𝐧𝐝\&\{E:\mathbf{end}\}& { italic_E : bold_end }. The latter ensures that S𝑆Sitalic_S is controllable. If we consider the constraints imposed by the Definition 3 on fair asynchronous subtyping relations, we can conclude that \mathcal{R}caligraphic_R should contain a pair of types (T,S)superscript𝑇superscript𝑆(T^{\prime},S^{\prime})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) where Tsuperscript𝑇T^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is the type corresponding to the new state of the queue machine (reached after the above sequence of output selections {{B1$Bn$$}}q{s}superscriptsubscriptsubscriptsuperscript𝐵currency-dollar1subscriptsuperscript𝐵currency-dollarsubscript𝑛currency-dollarsuperscript𝑞𝑠{\{\!\!\{{B^{\$}_{1}\cdots B^{\$}_{n_{\$}}}\}\!\!\}}_{q^{\prime}}^{\{s\}}{ { italic_B start_POSTSUPERSCRIPT $ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUPERSCRIPT $ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT $ end_POSTSUBSCRIPT end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT start_POSTSUPERSCRIPT { italic_s } end_POSTSUPERSCRIPT to be emitted by the queue machine after having consumed $currency-dollar\$$) and Ssuperscript𝑆S^{\prime}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is like S𝑆Sitalic_S, with the difference that before the output selection there is a sequence of input branchings, each one with only one label, corresponding with the sequence of symbols B1$Bn$$subscriptsuperscript𝐵currency-dollar1subscriptsuperscript𝐵currency-dollarsubscript𝑛currency-dollarB^{\$}_{1}\cdots B^{\$}_{n_{\$}}italic_B start_POSTSUPERSCRIPT $ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUPERSCRIPT $ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_n start_POSTSUBSCRIPT $ end_POSTSUBSCRIPT end_POSTSUBSCRIPT in the queue after the first computation step. This reasoning can be repeatedly applied to prove that \mathcal{R}caligraphic_R should also contain other pairs of types (T′′,S′′)superscript𝑇′′superscript𝑆′′(T^{\prime\prime},S^{\prime\prime})( italic_T start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ), one for each configuration (q′′,γ′′)superscript𝑞′′superscript𝛾′′(q^{\prime\prime},\gamma^{\prime\prime})( italic_q start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_γ start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) reachable in the queue machine M𝑀Mitalic_M. Consider now the pair (Tf,Sf)subscript𝑇𝑓subscript𝑆𝑓(T_{f},S_{f})\in\mathcal{R}( italic_T start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_S start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ) ∈ caligraphic_R corresponding to the terminating configuration (q,ϵ)superscript𝑞italic-ϵ(q^{\prime},\epsilon)( italic_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_ϵ ). The type Tfsubscript𝑇𝑓T_{f}italic_T start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT, as all the types representing states in the queue machine, starts with an input branching. The type Sfsubscript𝑆𝑓S_{f}italic_S start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT, on the other hand, represents the empty queue, so it is μ𝐭.{A:&{A:𝐭}}AΓ{E:&{E:𝐞𝐧𝐝}}formulae-sequence𝜇𝐭direct-sumsubscriptconditional-set𝐴conditional-set𝐴𝐭𝐴Γconditional-set𝐸conditional-set𝐸𝐞𝐧𝐝\mu\mathbf{\mathbf{t}}.\oplus\{{A}:{\&\{A:\mathbf{t}\}}\}_{A\in\Gamma}\cup\{E:% \&\{E:\mathbf{end}\}\}italic_μ bold_t . ⊕ { italic_A : & { italic_A : bold_t } } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : & { italic_E : bold_end } }, i.e. it is like [[M,E]]delimited-[]𝑀𝐸[\![M,E]\!][ [ italic_M , italic_E ] ] but without input branchings before the output selection. This means that (Tf,Sf)subscript𝑇𝑓subscript𝑆𝑓(T_{f},S_{f})( italic_T start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT , italic_S start_POSTSUBSCRIPT italic_f end_POSTSUBSCRIPT ) does not satisfy the item for input selection in Definition 3. Hence \mathcal{R}caligraphic_R cannot be a fair asynchronous subtyping, but this contradicts the above initial assumption about \mathcal{R}caligraphic_R being a fair asynchronous session subtyping.

We now move to the if part. Assume that the queue machine M𝑀Mitalic_M does not terminate. We show that there exists a fair asynchronous subtyping relation \mathcal{R}caligraphic_R that contains the pair (T,S)𝑇𝑆(T,S)( italic_T , italic_S ), hence TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S. There are two kinds of pairs in \mathcal{R}caligraphic_R: (i) the pairs discussed in the above only-if part of the proof that corresponds to the path in the subtyping simulation game that reproduces the computation of the queue machine M𝑀Mitalic_M, and (ii) other pairs corresponding to alternative paths. The pairs of types (i) satisfy the constraints imposed by Definition 3 because output selections of the l.h.s. type can always be mimicked by the r.h.s. type (that always include an output selection after a sequence of input branchings with only one label), and input branchings can always be mimicked by the r.h.s. type because under the assumption that the queue machine does not terminate, the queue is always non-empty during the computation. Also the pairs of type (ii) satisfy the constraints imposed by Definition 3. In fact, these pairs are generated considering the alternative branches in the l.h.s. types {{B1Bm}}r𝒯superscriptsubscriptsubscript𝐵1subscript𝐵𝑚𝑟𝒯{\{\!\!\{{B_{1}\cdots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}{ { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT in Definition 3.1, namely, the branches corresponding with the labels A𝐴Aitalic_A and E𝐸Eitalic_E in the definition, that we report here for reader convenience:

{{B1Bm}}r𝒯={[[[r]]]𝒯if m=0({B1:{{B2Bm}}r𝒯}{A:V}AΓ{B1}{E:V})otherwise\begin{array}[]{l}{\{\!\!\{{B_{1}\cdots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}\!=\!% \left\{\!\!\begin{array}[]{ll}\!{[\![\![{r}]\!]\!]}^{\mathcal{T}}&\text{if }m=% 0\\ \begin{array}[]{ll}\!\!\!\!\oplus&\!\!\!\!\big{(}\big{\{}B_{1}:{\{\!\!\{{B_{2}% \ldots B_{m}}\}\!\!\}}_{r}^{\mathcal{T}}\big{\}}\cup\\ &\!\big{\{}{A:V}\big{\}}_{A\in\Gamma\setminus\{B_{1}\}}\cup\{E:V^{\prime}\}% \big{)}\end{array}&\text{otherwise}\end{array}\right.\end{array}start_ARRAY start_ROW start_CELL { { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ⋯ italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT = { start_ARRAY start_ROW start_CELL [ [ [ italic_r ] ] ] start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT end_CELL start_CELL if italic_m = 0 end_CELL end_ROW start_ROW start_CELL start_ARRAY start_ROW start_CELL ⊕ end_CELL start_CELL ( { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : { { italic_B start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT … italic_B start_POSTSUBSCRIPT italic_m end_POSTSUBSCRIPT } } start_POSTSUBSCRIPT italic_r end_POSTSUBSCRIPT start_POSTSUPERSCRIPT caligraphic_T end_POSTSUPERSCRIPT } ∪ end_CELL end_ROW start_ROW start_CELL end_CELL start_CELL { italic_A : italic_V } start_POSTSUBSCRIPT italic_A ∈ roman_Γ ∖ { italic_B start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT } end_POSTSUBSCRIPT ∪ { italic_E : italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } ) end_CELL end_ROW end_ARRAY end_CELL start_CELL otherwise end_CELL end_ROW end_ARRAY end_CELL end_ROW end_ARRAY

with V=μ𝐭.({A:𝐭}AΓ{E:V})formulae-sequence𝑉𝜇𝐭direct-sumsubscriptconditional-set𝐴𝐭𝐴Γconditional-set𝐸superscript𝑉V=\mu\mathbf{\mathbf{t}}.\big{(}\oplus\{{A}:{\mathbf{t}}\}_{A\in\Gamma}\cup\{E% :V^{\prime}\}\big{)}italic_V = italic_μ bold_t . ( ⊕ { italic_A : bold_t } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT } ) and V=μ𝐭.(&{A:𝐭}AΓ{E:𝐞𝐧𝐝})formulae-sequencesuperscript𝑉𝜇𝐭subscriptconditional-set𝐴𝐭𝐴Γconditional-set𝐸𝐞𝐧𝐝V^{\prime}=\mu\mathbf{\mathbf{t}}.\big{(}\&\{{A}\!:\!{\mathbf{t}}\}_{A\in% \Gamma}\cup\{E:\mathbf{end}\}\big{)}italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = italic_μ bold_t . ( & { italic_A : bold_t } start_POSTSUBSCRIPT italic_A ∈ roman_Γ end_POSTSUBSCRIPT ∪ { italic_E : bold_end } ). The l.h.s. type in the pairs (T,S)superscript𝑇superscript𝑆(T^{\prime},S^{\prime})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) associated with these branches, are of two kinds: (a) they are able to recursively perform all possible outputs until the label E𝐸Eitalic_E is selected (type V𝑉Vitalic_V), or (b) they are able to recursively perform all possible inputs until the label E𝐸Eitalic_E is selected (type Vsuperscript𝑉V^{\prime}italic_V start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT). In the first case (a), the constraints in Definition 3 are satisfied because the r.h.s. type is always able to mimick output selections (see the above observation). In the second case (b), we have that the output E𝐸Eitalic_E has been previously selected by the last pair of kind (a) considered. Hence, the r.h.s. type is a sequence of input branchings, with only one label, where all inputs excluding the last one are different from E𝐸Eitalic_E, and the last one, having label E𝐸Eitalic_E, has continuation 𝐞𝐧𝐝𝐞𝐧𝐝\mathbf{end}bold_end. This guarantees that all these pairs satisfy the constraints in Definition 3, under the assumption that also a final pair (𝐞𝐧𝐝,𝐞𝐧𝐝)𝐞𝐧𝐝𝐞𝐧𝐝(\mathbf{end},\mathbf{end})( bold_end , bold_end ) belongs to \mathcal{R}caligraphic_R. We the conclude by observing that we have proved the existence of a fair session subtyping relation \mathcal{R}caligraphic_R such that (T,S)𝑇𝑆(T,S)\in\mathcal{R}( italic_T , italic_S ) ∈ caligraphic_R (in that this is the first pair of the kind (i) above), hence we have that TS𝑇𝑆T\operatorname{\leq}Sitalic_T ≤ italic_S.

A.5. Soundness of the Algorithm w.r.t. Fair Asynchronous Subtyping

See 13

Proof A.14.

We proceed by induction. If h=11h=1italic_h = 1, the thesis directly follows from the fact that 𝒯1superscript𝒯1\mathcal{T}^{1}caligraphic_T start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT is contained in a simulation tree.

If h>11h>1italic_h > 1, by inductive hypothesis we have that the thesis holds for 𝒯h1superscript𝒯1\mathcal{T}^{h-1}caligraphic_T start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT. We prove that the thesis holds also for 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT showing that there exists a simulation tree including mm𝑚superscript𝑚m\twoheadrightarrow{}m^{\prime}italic_m ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜vSjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) if and only if there exists a simulation tree including tt𝑡superscript𝑡t\twoheadrightarrow{}t^{\prime}italic_t ↠ italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with tsuperscript𝑡t^{\prime}italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜v+1SjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣1superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}+1}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). The proof is by case analysis, considering the three possible steps in the subtyping simulation game at the basis of the definition of \twoheadrightarrow{}.

If T𝑇Titalic_T starts with a recursive definition, the thesis trivially holds because \twoheadrightarrow{} simply modify the l.h.s. type by unfolding its initial recursion and leaves the r.h.s. type unchanged.

If T𝑇Titalic_T starts with an input branching, by Definition 3 we have that the r.h.s. type contains an entire context 𝒜𝒜\mathcal{A}caligraphic_A in its growing holes. We initially consider mm𝑚superscript𝑚m\twoheadrightarrow{}m^{\prime}italic_m ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜vSjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). This means that by applying 𝗎𝗇𝖿𝗈𝗅𝖽(\mathsf{unfold}(sansserif_unfold () to the r.h.s. type we obtain an input context starting with an input branching satisfying the constraints imposed by Definition 3. The step of the subtyping simulation game corresponding to mm𝑚superscript𝑚m\twoheadrightarrow{}m^{\prime}italic_m ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT selects a branch of the input branching such that its continuation 𝒜′′𝒜vSjjJJSkkKsuperscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}}\lfloor S^{\prime}_{j% }\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K}caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT is controllable. Now consider t𝑡titalic_t with label (T,𝒜𝒜v+1SjjJJSkkK)𝑇superscript𝒜superscriptdelimited-⟨⟩superscript𝒜𝑣1superscriptsubscript𝑆𝑗𝑗𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾(T,\mathcal{A}^{\prime}\langle\mathcal{A}^{v+1}\lfloor S_{j}\rfloor^{j\in J}% \rangle^{J}\lfloor S_{k}\rfloor^{k\in K})( italic_T , caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). The application of 𝗎𝗇𝖿𝗈𝗅𝖽(\mathsf{unfold}(sansserif_unfold () modifies the outer context in the same way thus obtaining a type starting with the same input branching, simply with an additional nesting of 𝒜𝒜\mathcal{A}caligraphic_A in the holes in J𝐽Jitalic_J. The continuation 𝒜′′𝒜v+1SjjJJSkkKsuperscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣1superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}+1}\lfloor S^{\prime}_% {j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K}caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT is also controllable because it is an input contexts with the set of indexed holes, hence the same set of types Sjsubscriptsuperscript𝑆𝑗S^{\prime}_{j}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT and Sksubscriptsuperscript𝑆𝑘S^{\prime}_{k}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT. Hence it is possible to apply a corresponding step in the subtyping simulation game tt𝑡superscript𝑡t\twoheadrightarrow{}t^{\prime}italic_t ↠ italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with tsuperscript𝑡t^{\prime}italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜v+1SjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣1superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}+1}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). Notice that the same reasoning can be applied assuming that tt𝑡superscript𝑡t\twoheadrightarrow{}t^{\prime}italic_t ↠ italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with tsuperscript𝑡t^{\prime}italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜v+1SjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣1superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}+1}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) to prove that there exists also the corresponding step in the subtyping simulation game mm𝑚superscript𝑚m\twoheadrightarrow{}m^{\prime}italic_m ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. In this case we use the assumption that in the growing holes of the r.h.s. type of the label of m𝑚mitalic_m we have an entire context 𝒜𝒜\mathcal{A}caligraphic_A, thus guaranteeing the presence of the same Sjsubscriptsuperscript𝑆𝑗S^{\prime}_{j}italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT in all the continuations of the initial input branching present in the outer context.

If T𝑇Titalic_T starts with an output selection, we initially consider mm𝑚superscript𝑚m\twoheadrightarrow{}m^{\prime}italic_m ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜vSjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). This means that by applying 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽()𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽\mathsf{selUnfold}()sansserif_selUnfold ( ) to the r.h.s. type we obtain an input context filled with types starting with output selections satisfying the constraints imposed by Definition 3. Notice that the application of 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽()𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽\mathsf{selUnfold}()sansserif_selUnfold ( ) to the outer input context does not remove holes, but at most replicates some of them. Moreover, the application of 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽()𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽\mathsf{selUnfold}()sansserif_selUnfold ( ) applies to the innermost types Sjsubscript𝑆𝑗S_{j}italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT and Sksubscript𝑆𝑘S_{k}italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT by unfolding the variables inside outputs replacing them with their definitions (already present in Sjsubscript𝑆𝑗S_{j}italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT and Sksubscript𝑆𝑘S_{k}italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT given that these are closed terms). The considered step in the subtyping simulation game modifies (the unfoldings of) Sjsubscript𝑆𝑗S_{j}italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT and Sksubscript𝑆𝑘S_{k}italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT by resolving initial output selections, thus obtaining Sjsuperscriptsubscript𝑆𝑗S_{j}^{\prime}italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and Sksuperscriptsubscript𝑆𝑘S_{k}^{\prime}italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. Now consider t𝑡titalic_t with label (T,𝒜𝒜v+1SjjJJSkkK)𝑇superscript𝒜superscriptdelimited-⟨⟩superscript𝒜𝑣1superscriptsubscript𝑆𝑗𝑗𝐽𝐽superscriptsubscript𝑆𝑘𝑘𝐾(T,\mathcal{A}^{\prime}\langle\mathcal{A}^{v+1}\lfloor S_{j}\rfloor^{j\in J}% \rangle^{J}\lfloor S_{k}\rfloor^{k\in K})( italic_T , caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). What we have just observed about the step mm𝑚superscript𝑚m\twoheadrightarrow{}m^{\prime}italic_m ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT of subtyping simulation game, holds also for this new pair of types. The application of 𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽()𝗌𝖾𝗅𝖴𝗇𝖿𝗈𝗅𝖽\mathsf{selUnfold}()sansserif_selUnfold ( ) respectively modifies the outer input context and the inner types Sjsubscript𝑆𝑗S_{j}italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT and Sksubscript𝑆𝑘S_{k}italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT in the same way, and also the same resolution of the initial output selections in Sjsubscript𝑆𝑗S_{j}italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT and Sksubscript𝑆𝑘S_{k}italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT is possible. Hence there exists tt𝑡superscript𝑡t\twoheadrightarrow{}t^{\prime}italic_t ↠ italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with tsuperscript𝑡t^{\prime}italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜v+1SjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣1superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}+1}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). Notice that the same reasoning can be applied assuming that tt𝑡superscript𝑡t\twoheadrightarrow{}t^{\prime}italic_t ↠ italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT with tsuperscript𝑡t^{\prime}italic_t start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with (T,𝒜′′𝒜v+1SjjJJSkkK)superscript𝑇superscript𝒜′′superscriptdelimited-⟨⟩superscript𝒜superscript𝑣1superscriptsubscriptsuperscript𝑆𝑗𝑗𝐽𝐽superscriptsubscriptsuperscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{\prime\prime}\langle\mathcal{A}^{v^{\prime}+1}\lfloor S% ^{\prime}_{j}\rfloor^{j\in J}\rangle^{J}\lfloor S^{\prime}_{k}\rfloor^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⟨ caligraphic_A start_POSTSUPERSCRIPT italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⟩ start_POSTSUPERSCRIPT italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) to prove that there exists also the corresponding step in the subtyping simulation game mm𝑚superscript𝑚m\twoheadrightarrow{}m^{\prime}italic_m ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

See 14

Proof A.15.

We proceed by induction on the length of nn𝑛superscriptsuperscript𝑛n\twoheadrightarrow\!\!{}^{*}\,n^{\prime}italic_n ↠ start_FLOATSUPERSCRIPT ∗ end_FLOATSUPERSCRIPT italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

If the length is 0, then nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is the root of 𝒯𝒯\mathcal{T}caligraphic_T hence its label is obviously in 𝒯1superscript𝒯1\mathcal{T}^{1}caligraphic_T start_POSTSUPERSCRIPT 1 end_POSTSUPERSCRIPT.

If the length is greater than 1, consider nn′′n𝑛superscriptsuperscript𝑛′′superscript𝑛n\twoheadrightarrow\!\!{}^{*}\,n^{\prime\prime}\twoheadrightarrow{}n^{\prime}italic_n ↠ start_FLOATSUPERSCRIPT ∗ end_FLOATSUPERSCRIPT italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ↠ italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. By inductive hypothesis we have that λ(n′′)𝜆superscript𝑛′′\lambda(n^{\prime\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) is a label present either in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT, for some hhitalic_h, or in 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)=(N,n0,,λ)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆superscript𝑁superscriptsubscript𝑛0superscript𝜆\mathit{simtree}(T^{\prime},S^{\prime})=(N^{\prime},n_{0}^{\prime},% \twoheadrightarrow,\lambda^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_N start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , ↠ , italic_λ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) with TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

We start from the latter case, i.e., there exists m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT in 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)=(N,n0,,λ)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆superscript𝑁superscriptsubscript𝑛0superscript𝜆\mathit{simtree}(T^{\prime},S^{\prime})=(N^{\prime},n_{0}^{\prime},% \twoheadrightarrow,\lambda^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_N start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , ↠ , italic_λ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) such that λ(m′′)=λ(n′′)superscript𝜆superscript𝑚′′𝜆superscript𝑛′′\lambda^{\prime}(m^{\prime\prime})=\lambda(n^{\prime\prime})italic_λ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ( italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) = italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ). We have that there exists m′′msuperscript𝑚′′superscript𝑚m^{\prime\prime}\twoheadrightarrow{}m^{\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT in 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆\mathit{simtree}(T^{\prime},S^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) s.t. λ(m)=λ(n)superscript𝜆superscript𝑚𝜆superscript𝑛\lambda^{\prime}(m^{\prime})=\lambda(n^{\prime})italic_λ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ( italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

We now consider the former case, i.e., there exists one node in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT, for some hhitalic_h, labeled with λ(n′′)𝜆superscript𝑛′′\lambda(n^{\prime\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ). Let m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT be such node. There are two possibilities, either (i) the node m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is a leaf in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT, or (ii) it is not a leaf. In the case (ii) we have that 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT contains m′′msuperscript𝑚′′superscript𝑚m^{\prime\prime}\twoheadrightarrow{}m^{\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, with msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ). If m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is a leaf, we consider the four kinds of leaves separately.

If m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is a leaf of type 2a, then there exists an ancestor m′′′superscript𝑚′′′m^{\prime\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT of m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT with the same label λ(n′′)𝜆superscript𝑛′′\lambda(n^{\prime\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ). Given that the ancestor is not a leaf, 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT contains m′′′msuperscript𝑚′′′superscript𝑚m^{\prime\prime\prime}\twoheadrightarrow{}m^{\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, with msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

If m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is a leaf of type 2b in 𝒯𝒯\mathcal{T}caligraphic_T, we have λ(n′′)=𝜆superscript𝑛′′absent\lambda(n^{\prime\prime})=italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) = (T,𝒜h+1SjjJSkkK)superscript𝑇superscript𝒜1superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾(T^{\prime},\mathcal{A}^{h+1}\lfloor S_{j}\rfloor^{j\in J}\lfloor S_{k}\rfloor% ^{k\in K})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT italic_h + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). The node n′′superscript𝑛′′n^{\prime\prime}italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT has an ancestor n′′′superscript𝑛′′′n^{\prime\prime\prime}italic_n start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT s.t. λ(n′′′)=(T,𝒜hSjjJSkkK)𝜆superscript𝑛′′′superscript𝑇superscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda(n^{\prime\prime\prime})=(T^{\prime},\mathcal{A}^{h}\lfloor S_{j}% \rfloor^{j\in J}\lfloor S_{k}\rfloor^{k\in K})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ) = ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). Consider now the corresponding node m′′′superscript𝑚′′′m^{\prime\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT in 𝒯h+1superscript𝒯1\mathcal{T}^{h+1}caligraphic_T start_POSTSUPERSCRIPT italic_h + 1 end_POSTSUPERSCRIPT. We have that m′′′superscript𝑚′′′m^{\prime\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT is labeled with (T,𝒜h+1SjjJSkkK)=λ(n′′)superscript𝑇superscript𝒜1superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾𝜆superscript𝑛′′(T^{\prime},\mathcal{A}^{h+1}\lfloor S_{j}\rfloor^{j\in J}\lfloor S_{k}\rfloor% ^{k\in K})=\lambda(n^{\prime\prime})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT italic_h + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) = italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ). Given that m′′′superscript𝑚′′′m^{\prime\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT is not a leaf, 𝒯h+1superscript𝒯1\mathcal{T}^{h+1}caligraphic_T start_POSTSUPERSCRIPT italic_h + 1 end_POSTSUPERSCRIPT contains m′′′msuperscript𝑚′′′superscript𝑚m^{\prime\prime\prime}\twoheadrightarrow{}m^{\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, with msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

If m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is a leaf of type 2c in 𝒯𝒯\mathcal{T}caligraphic_T, we have λ(n′′)=(T,𝒜hSjjJSkkK)𝜆superscript𝑛′′superscript𝑇superscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda(n^{\prime\prime})=(T^{\prime},\mathcal{A}^{h}\lfloor S_{j}\rfloor^{j% \in J}\lfloor S_{k}\rfloor^{k\in K})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) = ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). We have two cases. If h=11h=1italic_h = 1, by definition of witness tree, T𝒜hSjjJSkkKsuperscript𝑇superscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾T^{\prime}\operatorname{\leq}\mathcal{A}^{h}\lfloor S_{j}\rfloor^{j\in J}% \lfloor S_{k}\rfloor^{k\in K}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT. The node n′′superscript𝑛′′n^{\prime\prime}italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT has the same label as the root of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,𝒜hSjjJSkkK)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾\mathit{simtree}(T^{\prime},\mathcal{A}^{h}\lfloor S_{j}\rfloor^{j\in J}% \lfloor S_{k}\rfloor^{k\in K})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). Hence such a simulation tree includes a transition from its root to a node labeled with λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ). If h>11h>1italic_h > 1 the node n′′superscript𝑛′′n^{\prime\prime}italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT has an ancestor n′′′superscript𝑛′′′n^{\prime\prime\prime}italic_n start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT such that λ(n′′′)=(T,𝒜h+1SjjJSkkK)𝜆superscript𝑛′′′superscript𝑇superscript𝒜1superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾\lambda(n^{\prime\prime\prime})=(T^{\prime},\mathcal{A}^{h+1}\lfloor S_{j}% \rfloor^{j\in J}\lfloor S_{k}\rfloor^{k\in K})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ) = ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT italic_h + 1 end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ). Consider now the corresponding node m′′′superscript𝑚′′′m^{\prime\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT in 𝒯h1superscript𝒯1\mathcal{T}^{h-1}caligraphic_T start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT. We have that m′′′superscript𝑚′′′m^{\prime\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT is labeled with (T,𝒜hSjjJSkkK)=λ(n′′)superscript𝑇superscript𝒜superscriptsubscript𝑆𝑗𝑗𝐽superscriptsubscript𝑆𝑘𝑘𝐾𝜆superscript𝑛′′(T^{\prime},\mathcal{A}^{h}\lfloor S_{j}\rfloor^{j\in J}\lfloor S_{k}\rfloor^{% k\in K})=\lambda(n^{\prime\prime})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_j ∈ italic_J end_POSTSUPERSCRIPT ⌊ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ⌋ start_POSTSUPERSCRIPT italic_k ∈ italic_K end_POSTSUPERSCRIPT ) = italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ). Given that m′′′superscript𝑚′′′m^{\prime\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT is not a leaf, 𝒯h1superscript𝒯1\mathcal{T}^{h-1}caligraphic_T start_POSTSUPERSCRIPT italic_h - 1 end_POSTSUPERSCRIPT contains m′′′msuperscript𝑚′′′superscript𝑚m^{\prime\prime\prime}\twoheadrightarrow{}m^{\prime}italic_m start_POSTSUPERSCRIPT ′ ′ ′ end_POSTSUPERSCRIPT ↠ italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, with msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT labeled with λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

If m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT corresponds to leaf of type 2d in 𝒯𝒯\mathcal{T}caligraphic_T, we have that the label λ(n′′)𝜆superscript𝑛′′\lambda(n^{\prime\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) of m′′superscript𝑚′′m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT is the same as the label in the corresponding node in 𝒯𝒯\mathcal{T}caligraphic_T, i.e. (T,𝒜[Sk]kK)superscript𝑇superscript𝒜superscriptdelimited-[]subscript𝑆𝑘𝑘superscript𝐾(T^{\prime},\mathcal{A}^{\prime}[S_{k}]^{k\in K^{\prime}})( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT ). In fact labels of the leaves of type 2d in 𝒯𝒯\mathcal{T}caligraphic_T do not change when moving to 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT. This because the input context 𝒜superscript𝒜\mathcal{A}^{\prime}caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT does not include growing holes. By definition of witness tree we have that T𝒜[Sk]kKsuperscript𝑇superscript𝒜superscriptdelimited-[]subscript𝑆𝑘𝑘superscript𝐾T^{\prime}\operatorname{\leq}\mathcal{A}^{\prime}[S_{k}]^{k\in K^{\prime}}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT. The node n′′superscript𝑛′′n^{\prime\prime}italic_n start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT has the same label as the root of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,𝒜[Sk]kK)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝒜superscriptdelimited-[]subscript𝑆𝑘𝑘superscript𝐾\mathit{simtree}(T^{\prime},\mathcal{A}^{\prime}[S_{k}]^{k\in K^{\prime}})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , caligraphic_A start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ italic_S start_POSTSUBSCRIPT italic_k end_POSTSUBSCRIPT ] start_POSTSUPERSCRIPT italic_k ∈ italic_K start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT end_POSTSUPERSCRIPT ). Hence such a simulation tree includes a transition from its root to a node labeled with λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

See 15

Proof A.16.

Let 𝒯𝒯\mathcal{T}caligraphic_T be the witness subtree with root in n𝑛nitalic_n. By Proposition 14 we have that λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) is a label present either in 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT, for some hhitalic_h, or in 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)=(N,n0,,λ)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆superscript𝑁superscriptsubscript𝑛0superscript𝜆\mathit{simtree}(T^{\prime},S^{\prime})=(N^{\prime},n_{0}^{\prime},% \twoheadrightarrow,\lambda^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_N start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_n start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , ↠ , italic_λ start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) with TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. In the latter case the thesis trivially holds because all nodes msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT in 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆\mathit{simtree}(T^{\prime},S^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) are either successful or there exists mm′′superscript𝑚superscript𝑚′′m^{\prime}\twoheadrightarrow{}m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ↠ italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT. In the former case there are two cases: either there exists an intermediary node (non-leaf) in one 𝒯hsuperscript𝒯\mathcal{T}^{h}caligraphic_T start_POSTSUPERSCRIPT italic_h end_POSTSUPERSCRIPT, for some hhitalic_h, labeled with λ(n)𝜆superscript𝑛\lambda(n^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) is an intermediary, or such a node can be only in leaf positions. In the first case the thesis trivially holds because all intermediary nodes have successors. The second case can occur only for leaves of type 2c in 𝒯𝒯\mathcal{T}caligraphic_T, or corresponding to leaves of type 2d in 𝒯𝒯\mathcal{T}caligraphic_T. Both cases imply that λ(n)=(T,S)𝜆superscript𝑛superscript𝑇superscript𝑆\lambda(n^{\prime})=(T^{\prime},S^{\prime})italic_λ ( italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) with TSsuperscript𝑇superscript𝑆T^{\prime}\operatorname{\leq}S^{\prime}italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ≤ italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. Hence nsuperscript𝑛n^{\prime}italic_n start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT has the same label as the root of 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆\mathit{simtree}(T^{\prime},S^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) and, as above, the thesis trivially holds because all nodes msuperscript𝑚m^{\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT in 𝑠𝑖𝑚𝑡𝑟𝑒𝑒(T,S)𝑠𝑖𝑚𝑡𝑟𝑒𝑒superscript𝑇superscript𝑆\mathit{simtree}(T^{\prime},S^{\prime})italic_simtree ( italic_T start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_S start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) are either successful or there exists mm′′superscript𝑚superscript𝑚′′m^{\prime}\twoheadrightarrow{}m^{\prime\prime}italic_m start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ↠ italic_m start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT.