20. どうやって Liveness 特性を
検証すればよいのか?
時相論理演算⼦ <> を使って制約を定義し、
モデルファイルの PROPERTIES に指定します。
この例では、⻘と⾚に切り替わる歩⾏者⽤信
号と、⻘になったときに道路を渡ることのできる
歩⾏者からなるシステムを⽰している。
では信号が⻘にならなかったり、プロセスに fair
がついていない場合は何が起きるか?
道路を横断しようとしている歩⾏者と歩⾏者⽤信号機の連携システム
---- MODULE Crosswalk ----
(* --algorithm Crosswalk
variables signal ¥in {"green", "red"},
went_through = FALSE;
define
PedestrianHasCrossed == <>went_through
Flip(s) == IF s = "green" THEN "red" ELSE "green"
end define;
fair+ process Pedestrian = "pedestrian"
begin
Wait:
await signal = "green";
WentThrough:
went_through := TRUE;
end process;
fair process Signal = "signal"
begin
Switch:
while TRUE do
signal := Flip(signal);
end while;
end process;
end algorithm; *)
====
SPECIFICATION Spec
¥* Add statements after this line.
PROPERTIES PedestrianHasCrossed
21. Liveness 特性に違反してみると
Q3. Pedestrian を弱い公平性に変えると何が起きる?
¥* fair+ process Pedestrian = "pedestrian"
fair process Pedestrian = "pedestrian"
A3. 信号が⻘になった途端に歩⾏者がスタッタリングす
ることを延々と繰り返して歩⾏者が永遠に道路を
渡ることがでない可能性があります。
¥* fair process Signal = "signal"
process Signal = "signal"
A2. 信号機が⾚になった状態でクラッシュ停⽌ (無限
のスタッタリング) を起こした場合、歩⾏者は永遠
に道路を渡ることができません。
Q2. Signal から fair を消すと何が起きる?
Q1. もし信号が⼀度も⻘にならなかったら?
¥* Flip(s) == IF s = "green" THEN "red" ELSE "green"
Flip(s) == "red"
A1. 道路を横断することなく状態グラフの探索が終了するため検
証に失敗します。
22. どうやって Termination を検証
するのか?
-termination オプションはシステムの狩猟を検査
する簡易的な⽅法です。この Termination 特性
は以下のように書くこともできます。
PlusCal options (-termination)
---- MODULE InfiniteLoop ----
EXTENDS TLC
(* --fair algorithm InfiniteLoop
variables flag = FALSE;
begin
Loop:
while TRUE do
flag := ~flag;
end while;
Finish:
print "finish"
end algorithm; *)
====
抽象化されたシステム設計ではシステム全体の termination は必須というわけではない。Termination の代わりに独⾃の
終了条件を時相特性として定義し使⽤することができる。
SPECIFICATION Spec
PROPERTY Termination
¥* Add statements after this line.
𝑇𝑒𝑟𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛 ≝ ◇(∀𝑠𝑒𝑙𝑓 ∈ 𝑃𝑟𝑜𝑐𝑆𝑒𝑡: 𝑝𝑐 𝑠𝑒𝑙𝑓 = "Done")
この場合、たった 1 つのプロセスでも無限回のスタッタリングを起こすと制約
違反となるため、すべてのプロセスは fair 特性を保つ必要があります。
27. References
1. Use of Formal Methods at Amazon Web Services
https://lamport.azurewebsites.net/tla/formal-methods-amazon.pdf
2. How Amazon Web Services Uses Formal Methods
https://cacm.acm.org/magazines/2015/4/184701-how-amazon-web-services-uses-formal-methods/fulltext
3. FINAL FANTASY XV POCKET EDITION を⽀える AWS サーバレス技術
https://d1.awsstatic.com/events/jp/2018/summit/tokyo/customer/37.pdf
4. Proving the Correctness of Multiprocess Programs (1977) L. Lamport
https://ieeexplore.ieee.org/document/1702415
5. The TLA+ Video Course (2020) L. Lamport
http://lamport.azurewebsites.net/video/videos.html (recommended to watch first)
6. PlusCal / TLA⁺: An Annotated Cheat Sheet (2019) S.Merz
https://d3s.mff.cuni.cz/f/teaching/nswi101/pluscal.pdf
7. Summary of TLA⁺
https://lamport.azurewebsites.net/tla/summary-standalone.pdf
31. 逐次処理を記述するための構⽂
if 𝑃 then 𝐴;
elsif 𝐵;
elsif ⋯
else ⋯
end if;
Label:
while 𝑃 do
𝐴;
end while;
goto Label;
IF 𝑃 THEN 𝐴;
ELSE 𝐵;
END IF;
CASE 𝑃 -> 𝐴;
[] 𝑄 -> 𝐵;
[] 𝑅 -> 𝐶;
OTHER -> 𝐷;
PlusCal はオブジェクト指向や関数型のパラダイ
ムのように複雑な操作を簡単に書くための⾔語
機能を持っていない。
その理由はおそらく、それらが有限状態機械の
状態遷移を複雑にするためだと思われる。
構⽂; “else if” に相当
する機能はない
構⽂
式
TLA⁺ 構⽂ PlusCal 構⽂
”for” は⽤意されていない
これだけ?? 😇
See also: [6][7] for other language features.
33. Operators and Notations
TLA⁺ Notations Math
Expressions
Meanings
x := y Assign the value of 𝑦 to 𝑥.
x == 10 ≜ Define 𝑥 as 10.
x ¥in {A,B,C} 𝑥 ∈ {𝐴, 𝐵, 𝐶} Let 𝑥 be an element of the set {𝐴, 𝐵, 𝐶}.
x ¥in 1..9 𝑥 ∈ {1, … , 9} Let 𝑥 be an element of the set {1, … , 9}.
P /¥ Q 𝑃 ∧ 𝑄 Logical disjunction of 𝑃 and 𝑄.
P ¥/ Q 𝑃 ∨ 𝑄 Logical conjunction of 𝑃 and 𝑄.
~P ¬𝑃 Negation of 𝑃.
x = y 𝑥 = 𝑦 𝑥 equals to 𝑦.
x /= y 𝑥 ≠ 𝑦 𝑥 doesn’t equal to 𝑦.
P ¥equiv Q 𝑃 ≡ 𝑄 𝑃 equivalents to 𝑄.
¥A x ¥in S: P(x) ∀𝑥 ∈ 𝑆: 𝑃(𝑥) For all elements 𝑥 in the set 𝑆, 𝑃(𝑥) is satisfied.
¥E x ¥in S: P(x) ∃𝑥 ∈ 𝑆: 𝑃(𝑥) There exists an element x in the set S that satisfies P(x).
+,-,*,/,% Arithmetic operators
x ¥o y 𝑥 ∘ 𝑦 Concatenate the tuples or strings.
CHOOSE x ¥in S: P(x) Select arbitrarily element 𝑥 from the set 𝑆 that satisfies 𝑃(𝑥).
TLA⁺ Nots. Meanings
"abc" String literal.
<<A,B,C>> Tuple or list (𝐴, 𝐵, 𝐶)
[a|->1,b|->2] Struct {a:1, b:2}
[i ¥in 1..3|->i*i] Tuple (1, 4, 9)
ToString(number)
Len(tuple)
See also: [6][7] for other language features.