Skip to content

Commit 4bec618

Browse files
committed
v33 (RefinementFair): Prove BlockingQueueFair implements BlockingQueueSplit.
1 parent 3e6bce9 commit 4bec618

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

BlockingQueueFair.tla

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,84 @@ THEOREM ITypeInv == Spec => []TypeInv
146146
<1>3. QED BY <1>1, <1>2, PTL DEF Spec
147147

148148
-----------------------------------------------------------------------------
149+
150+
LEMMA EmptySeqRange == ASSUME NEW S, NEW seq \in Seq(S)
151+
PROVE seq = <<>> <=> Range(seq) = {}
152+
BY Isa DEF Range
153+
154+
LEMMA RangeTail ==
155+
ASSUME NEW S, NEW ws \in Seq(S), IsInjective(ws)
156+
, ws # <<>>
157+
PROVE \E x \in Range(ws): Range(Tail(ws)) = Range(ws) \ {x}
158+
\* BY Z3 DEF Range, IsInjective \* Proof goes through with Tail
159+
\* re-defined with the CASE
160+
\* statement omitted, which is
161+
\* equivalent here due to
162+
\* 'ws # <<>>' assumption.
163+
164+
-----------------------------------------------------------------------------
165+
166+
(* Prove BlockingQueueFair implements BlockingQueueSplit *)
167+
THEOREM Spec => BQS!Spec
168+
<1> USE Assumption DEF Range
169+
<1>1. Init => BQS!Init
170+
BY DEF Init, BQS!Init
171+
<1>2. TypeInv /\ [Next]_vars => [BQS!Next]_BQS!vars
172+
<2> SUFFICES ASSUME TypeInv,
173+
[Next]_vars
174+
PROVE [BQS!Next]_BQS!vars
175+
OBVIOUS
176+
<2>1. ASSUME NEW p \in Producers,
177+
Put(p, p)
178+
PROVE [BQS!Next]_BQS!vars
179+
<3>1. CASE /\ Len(buffer) < BufCapacity
180+
/\ buffer' = Append(buffer, p)
181+
/\ NotifyOther(waitSeqC)
182+
/\ UNCHANGED waitSeqP
183+
<4>1. CASE /\ waitSeqC = <<>>
184+
/\ UNCHANGED waitSeqC
185+
BY <4>1, <2>1, <3>1, Isa
186+
DEF Put, BQS!Next, BQS!vars, BQS!Put, BQS!NotifyOther
187+
<4>2. CASE /\ waitSeqC # <<>>
188+
/\ waitSeqC' = Tail(waitSeqC)
189+
BY <4>2, <2>1, <3>1, EmptySeqRange, RangeTail, Isa
190+
DEF TypeInv, Put, BQS!Next, BQS!vars, BQS!Put, BQS!NotifyOther
191+
<4>3. QED
192+
BY <3>1, <4>1, <4>2 DEF NotifyOther
193+
<3>2. CASE /\ Len(buffer) = BufCapacity
194+
/\ Wait(waitSeqP, p)
195+
/\ UNCHANGED waitSeqC
196+
BY <2>1, <3>2
197+
DEF Wait, BQS!Next, BQS!vars, BQS!Put, BQS!Wait
198+
<3>3. QED
199+
BY <2>1, <3>1, <3>2 DEF Put
200+
<2>2. ASSUME NEW c \in Consumers,
201+
Get(c)
202+
PROVE [BQS!Next]_BQS!vars
203+
<3>1. CASE /\ buffer # <<>>
204+
/\ buffer' = Tail(buffer)
205+
/\ NotifyOther(waitSeqP)
206+
/\ UNCHANGED waitSeqC
207+
<4>1. CASE /\ waitSeqP = <<>>
208+
/\ UNCHANGED waitSeqP
209+
BY <4>1, <2>2, <3>1, Isa
210+
DEF Get, BQS!Next, BQS!vars, BQS!Get, BQS!NotifyOther
211+
<4>2. CASE /\ waitSeqP # <<>>
212+
/\ waitSeqP' = Tail(waitSeqP)
213+
BY <4>2, <2>2, <3>1, EmptySeqRange, RangeTail, Isa
214+
DEF TypeInv, Get, BQS!Next, BQS!vars, BQS!Get, BQS!NotifyOther
215+
<4>3. QED
216+
BY <3>1, <4>1, <4>2 DEF NotifyOther
217+
<3>2. CASE /\ buffer = <<>>
218+
/\ Wait(waitSeqC, c)
219+
/\ UNCHANGED waitSeqP
220+
BY <2>2, <3>2 DEF Wait, BQS!Next, BQS!vars, BQS!Get, BQS!Wait
221+
<3>3. QED
222+
BY <2>2, <3>1, <3>2 DEF Get
223+
<2>3. CASE UNCHANGED vars
224+
BY <2>3 DEF vars, BQS!Next, BQS!vars
225+
<2>4. QED
226+
BY <2>1, <2>2, <2>3 DEF Next
227+
<1>3. QED BY <1>1, <1>2, ITypeInv, PTL DEF Spec, BQS!Spec
228+
149229
=============================================================================

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ This tutorial is work in progress. More chapters will be added in the future. In
1313

1414
--------------------------------------------------------------------------
1515

16+
### v33 (Refinement Fair): Prove BlockingQueueFair implements BlockingQueueSplit.
17+
18+
A proof showing that ```BlockingQueueSplit``` implements ```BlockingQueueSplit```. Two lemmas show that it is sometimes necessary to prove simpler facts first to prove the main theorem.
19+
20+
Compared to the previous proofs, this one is far more involved and more realistically reflects the efforts require to write proofs; the refinement proof took approximately three weeks. Three weeks is quite an investment considering that the correctness of the refinement seems straight forward in the first place. However, three weeks also includes the work to detect and help with a fix for a [regression in TLAPS 1.4.4](https://github.com/tlaplus/tlapm/releases/tag/v1.4.5), identifying [two](https://github.com/tlaplus/tlaplus/issues/434) Toolbox [issues](https://github.com/tlaplus/tlaplus/issues/433), and familiarizing myself with the TLAPS [build](https://github.com/tlaplus/tlapm/blob/master/tools/installer/tlaps-release.sh.in) and [development](https://www.youtube.com/watch?v=Eu46FmhpR_0&feature=youtu.be) process.
21+
1622
### v32 (Refinement Fair): Prove TypeInv is an inductive invariant of BlockingQueueFair.
1723

1824
As a first step of proving that ```BlockingQueueFair``` refines ```BlockingQueueSplit```, we once again prove inductiveness of ```TypeInv```.

0 commit comments

Comments
 (0)