Created
February 19, 2012 16:19
-
-
Save siritori/1864495 to your computer and use it in GitHub Desktop.
二分探索木をAlloyで定義してみた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open util/ordering[Node] | |
sig Node { | |
lhs : lone Node, | |
rhs : lone Node | |
} | |
fact { | |
// 葉をたどればすべての要素が取得できるrootがただひとつ存在する | |
one root : Node | Node = root.*(lhs+rhs) | |
// 任意の節において成り立つ | |
all n : Node { | |
// 左葉と右葉には共通する節が存在しない | |
no n.lhs.*(lhs+rhs) & n.rhs.*(lhs+rhs) | |
// 節間の葉関係は循環しない | |
not n in n.^(lhs+rhs) | |
// 葉が存在するなら、それは left < n <= right という関係になる | |
one n.lhs => lt [n.lhs, n] | |
one n.rhs => lte[n, n.rhs] | |
} | |
} | |
pred show {} | |
run show for 10 Node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment