• Tidak ada hasil yang ditemukan

Systems and Contracts

Chapter V: Reactive Contracts

5.2 Systems and Contracts

To keep things concise without losing generality, we will only cover assume- guarantee contracts defined over a common set of Boolean variables V called thealphabet. For any set 𝑋, let π‘‹πœ” be the set of infinite sequences generated from 𝑋, namely {hπ‘₯𝑖i∞

𝑖=0 = hπ‘₯0, π‘₯1, . . .i | π‘₯𝑖 ∈ 𝑋}, π‘‹βˆ— be the set of finite sequences, and

2𝑋 be the powerset of 𝑋. Define π‘‹βˆž as π‘‹βˆ—βˆͺ π‘‹πœ”. Inimplementationsa contract.

accordance with the metatheory, we term any pair of collections of environments and implementations a contract. The theory of assume-guarantee contracts is a model of the metatheory and can be described as follows.

Definition 5.2.1(Behaviors and Assertions). A behavior 𝜎 is an element ofB B (2V)πœ”. An assertion𝐴is a subset ofB, namely,𝐴 ∈2B.

We lift the set of all assertions 2B to a Boolean algebra by defining a unary operator

Β¬and two binary operators∧,∨on it in the standard way: if𝐴, 𝐴1, 𝐴2are assertions, then¬𝐴 B B \ 𝐴, 𝐴1∨ 𝐴2 B 𝐴1βˆͺ𝐴2, 𝐴1∧𝐴2 B 𝐴1∩𝐴2. The induced partial ordering relation≀ on 2B is simply the subset relation βŠ†. Additionally, we define a secondary binary operatorβ‡’in 𝐴1β‡’ 𝐴2as a shorthand for¬𝐴1∨𝐴2.

Acomponent 𝑀 is an assertion designated as such. Via locality assumptions, the assertion characterizing a component is often restricted to a subset ofV (with no constraints on variables outside the set). If 𝑀1 and 𝑀2are components, theinter- connectionbinary operatorβŠ• is defined by 𝑀1βŠ• 𝑀2 B 𝑀1βˆ§π‘€2. That is, the set of behaviors of the interconnection consists only of those common to (or witnessed by) both implementations. We note that depending on how the variables and asser- tions making up the components being interconnected are defined, βŠ• can assume the meaning of either a parallel, series, coproduct, or feedback connection (Censi, 2015). In fact, contracts and the corresponding algebra can be used to constrain components satisfying them so that the meaning of their interconnection will be clear.

Definition 5.2.2 (Contracts). An assume-guarantee contract C is a pair of asser- tions (𝐴, 𝐺), called the assumption and the guarantee respectively. The set of environments ofC, denoted byEC, captures all components𝐸 such that

𝐸 ≀ 𝐴. (5.1)

In other words,EC =2𝐴. The set of implementations ofC, denoted byMC, consists of all components𝑀 such that

βˆ€πΈ ∈ EC. 𝑀 βŠ•πΈ ≀ 𝐺 . (5.2)

Example 5.2.1. LetV ={π‘₯ , 𝑦},C =(𝐴, 𝐺)where𝐴 B {𝜎 | π‘₯ βˆˆπœŽπ‘– ⇔𝑖 mod 2= 0}, 𝐺 B {𝜎 | 𝑦 ∈ πœŽπ‘– ⇔ 𝑖 mod 2 β‰  0}, 𝜎1 B h{π‘₯},{𝑦},{π‘₯},βˆ…,{π‘₯},βˆ…, . . .i and 𝜎2 B h{π‘₯},{𝑦},{π‘₯},{𝑦}, . . .i. If𝐸 B {𝜎1, 𝜎2}, then𝐸 ∈ EC because𝜎1, 𝜎2 ∈ 𝐴.

Let 𝑀1 B {𝜎1} and 𝑀2 B {𝜎2}. Then 𝑀1 βˆ‰MC because 𝑀1βŠ• 𝐸 = {𝜎1} βˆ‰πΊ. However, one can check that 𝑀2 ∈ MC. Note that if 𝑀3 B βˆ…, then𝑀3 ∈ MC as well. The interpretation here is that𝑀3satisfies the assume-guarantee semantics of Cvacuously.

Since 2B is a Boolean algebra, we infer from inequality (5.2) and the definition of

βŠ• that 𝑀 is an implementation if βˆ€πΈ ∈ EC. 𝑀 ≀ ¬𝐸 ∨𝐺. Choosing 𝐸 = 𝐴 in inequality (5.1) gives 𝑀 ≀ ¬𝐴∨𝐺. Conversely, satisfying 𝑀 ≀ ¬𝐴∨𝐺 implies that 𝑀 is an implementation because¬𝐸 ∨𝐺 is antitone in𝐸. Thus, we have the following proposition.

Proposition 8. GivenC= (𝐴, 𝐺), a component𝑀 satisfies𝑀 ∈ MCif and only if

𝑀 ≀ 𝐴⇒ 𝐺 . (5.3)

Proposition 8 characterizes implementations 𝑀 of C as those components whose behaviors either do not conform to the behaviors specified in 𝐴 or are compatible with𝐺. Specifically, it says thatMC =2𝐴⇒𝐺. Furthermore, since

𝐴⇒ (𝐴⇒ 𝐺) =¬𝐴∨ (¬𝐴∨𝐺) =¬𝐴∨𝐺 = 𝐴 ⇒𝐺 , (5.4) inequalities (5.1) and (5.3) yield the following proposition.

Proposition 9. If C = (𝐴, 𝐺) and Cβˆ— = (𝐴, 𝐴 β‡’ 𝐺), then MC = MCβˆ— and EC =ECβˆ—.

It may be seen from equation (5.4) why any assume-guarantee contract of the form C = (𝐴, 𝐴 β‡’ 𝐺) is called saturated. By the metatheory, we will consider contracts that have the same sets of environments and implementations to be equal, and so by Proposition 9, every contract C has a unique saturated canonicalform Cβˆ—. This saturated form makes contract algebra more convenient and sheds light on the meaning of the conjunction operation, which motivates our development of

β€œreactive contracts.” To describe the conjunction, we will need the idea of contract refinement whose definition is repeated here for ease of reference.

Definition 5.2.3. We say contract C1 = (𝐴1, 𝐺1) refines a contract C2 = (𝐴2, 𝐺2) and writeC1 C2ifMC1 βŠ† M𝐢2 andE𝐢2 βŠ† E𝐢1.

Theconjunctionof two contractsC1andC2, denoted byC1∧ C2, is a contract that is their largest lower bound (or meet) with respect to . For any contract C, we

haveEC =2𝐴andMC =2𝐴⇒𝐺. Therefore, ifC ≀ C1,C2, then by Definition 5.2.3, MC βŠ† MC1∩ MC2 = 2𝐴1⇒𝐺1 ∩2𝐴2⇒𝐺2 = 2(𝐴1⇒𝐺1)∧(𝐴2⇒𝐺2) and 2𝐴1∨𝐴2 =2𝐴1 βˆͺ 2𝐴2 =EC1βˆͺ EC2 βŠ† EC (since the intersection/union of powersets of two sets is the powerset of their intersection/union). By the fact that (𝐴1 ⇒𝐺1) ∧ (𝐴2β‡’ 𝐺2) is saturated, we haveC1∧ C2= (𝐴1∨ 𝐴2,(𝐴1β‡’ 𝐺1) ∧ (𝐴2 ⇒𝐺2)). By induction, we can conclude the following:

Proposition 10. If for𝑖=1,2, . . . , 𝑛,𝐢𝑖are assume-guarantee contracts, then

βˆ§π‘›π‘–=1C𝑖 =(βˆ¨π‘›π‘–=1𝐴𝑖,βˆ§π‘›π‘–=1𝐴𝑖 β‡’ 𝐺𝑖). (5.5) Note that we can apply an analogous argument to the disjunction of contracts (defined as their join) to conclude that the set of all saturated contracts forms a complete lattice. Equation (5.5) shows that the β€œparametric contract” formalism given in (Kim, Arcak, and Seshia, 2017) is exactly the result of applying the conjunction operation to the constituent contracts. That is, if 𝑀 is an implementation of the conjunctionβˆ§π‘–C𝑖containing𝜎 such that𝜎 ∈𝐸 where𝐸 is an environment ofβˆ§π‘–C𝑖, then there exists at least a π‘˜ ∈ {1,2, . . . , 𝑛} such that 𝜎 ∈ π΄π‘˜ and for all such π‘˜, 𝜎 ∈ πΊπ‘˜. In other words, for any behavior 𝜎 in which the environment satisfies any assumption π΄π‘˜ in {𝐴1, 𝐴2, . . . , 𝐴𝑛}, the system must react by providing the corresponding guarantee πΊπ‘˜. Thus in contract conjunctions, 1) the reactions are defined by pairing each π΄π‘˜ with the correspondingπΊπ‘˜, and 2) π΄π‘˜ β‡’πΊπ‘˜ must hold over the sequence𝜎in its entirety. The second restriction is partially relaxed in the

β€œdynamic contract” formalism, used for instance in (Kim, Sadraddini, et al., 2017), where assumptions are allowed to change over fixed time intervals. Our reactive contract framework will 1) remove the one-to-one restriction to allow for a more flexible assumption-guarantee pairing process, 2) enforces immediate guarantee reactions to assumption changes directly on each element 𝜎 ∈ B, and 3) enables automated synthesis.

5.3 Reactive Contracts