我尝试了下面的Alloy4片段,发现自己对util / Natural模块的行为感到困惑。这些评论更详细地解释了意外情况。我希望有人能解释为什么会这样。
module weirdNatural
private open util/natural as nat
//Somehow, using number two obtained from incrementing one works as I expect, (ie, there is no
//number greater than it in {0,1,2}. but using number two obtained from the natrual/add function
//seems to work differently. why is that?
let twoViaAdd = nat/add[nat/One, nat/One]
let twoViaInc = nat/inc[nat/One]
pred biggerAdd {
some x: nat/Natural | nat/gt[x, twoViaAdd]
}
pred biggerInc {
some y: nat/Natural | nat/gt[y, twoViaInc]
}
//run biggerAdd for 10 but 3 Natural //does not work well, it does find a number gt2 in {0,1,2}
run biggerInc for 10 but 3 Natural //works as expected, it finds a number gt2 in {0,1,2,3}, but not in {0,1,2}
答案 0 :(得分:2)
感谢您提供此错误报告。你是绝对正确的,这是一种奇怪的行为。
Alloy4.2对整数的处理方式进行了一些修改; ,Alloy4.2中的+
和-
运算符始终被解释为集合并/差异,因此必须使用内置函数plus
/ minus
来表示算术加法/减法。另一方面, util / natural 模块(错误地)尚未更新为使用最新语法,这是您遇到的奇怪行为的根本原因(具体而言,{{1} }函数使用旧nat/add
运算符而不是+
,而plus
则不然。)
要解决此问题,您可以
nat/inc
的两个匹配项替换为<a> + <b>
plus[<a>, <b>]
)或