Qiita Conference 2025

Qiita史上最多!豪華12名のゲストが登壇

特別講演ゲスト(敬称略)

ymrl、成瀬允宣、鹿野壮、伊藤淳一、uhyo、徳丸浩、ミノ駆動、みのるん、桜庭洋之、tenntenn、けんちょん、こにふぁー

1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「形式手法入門」P157 「6.2.5 イベント駆動スタイル」

Posted at

割と分かり易い。
ただ、「どういう操作をすると目的の値が出るのか」
を検査するのにこの方法は使えない、よね。

eventDrivenStyle.als
// 「形式手法入門」P157 「6.2.5 イベント駆動スタイル」
open util/ordering [Time]
open util/natural

sig Time{}

sig State {
	a, b, c, n : Natural one -> Time,
	d : Natural
}{
	add[a.Time, add[b.Time, c.Time]] = n.Time // a + b + c = n
	a.Time = Zero or c.Time = Zero // a = 0 or c = 0
	gte[d, n.Time] and gt[d, Zero] // (d >= n) and (d > 0)
}

pred MLout[t, t' : Time] {
	gt[State.d, add[(State.a).t, (State.b).t]] and (State.c).t = Zero
	(State.a).t' = inc[(State.a).t]
	(State.b).t' = (State.b).t and (State.c).t' = (State.c).t
}

pred ILin[t,t' : Time] {
	gt[(State.a).t, Zero]
	(State.a).t' = dec[(State.a).t] and (State.b).t' = inc[(State.b).t]
	(State.c).t' = (State.c).t
}

pred ILout[t,t' : Time] {
	gt[(State.b).t, Zero] and (State.a).t = Zero
	(State.b).t' = dec[(State.b).t] and (State.c).t' = inc[(State.c).t]
	(State.a).t' = (State.a).t
}

pred MLin[t, t' : Time] {
	gt[(State.c).t, Zero]
	(State.c).t' = dec[(State.c).t]
	(State.a).t' = (State.a).t and (State.b).t' = (State.b).t
}

pred I [t : Time] {
	(State.a).t = Zero and (State.b).t = Zero
	and (State.c).t = Zero
}

pred T [t, t' : Time] {
	MLin[t,t'] or MLout[t,t'] or ILin[t,t'] or ILout[t,t']
}

pred Path1 {
	let t0 = first, t1 = next[t0], t2 = next[t1],
		t3 = next[t2], t4 = next[t3], t5 = next[t4] | {
			I[t0] and T[t0,t1] and T[t1,t2] and T[t2,t3] and T[t3,t4] and T[t4, t5]
			and (State.a).t5 = One
	}
}

// 以下のようにEvaluatorに入力すると、時間ごとの変数aの値が分かる
// ~(State.a)
run Path1 for 5 but 8 Time
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?