【发布时间】:2017-10-08 19:44:30
【问题描述】:
Software Abstractions 的第 293 页说这两者是等价的:
all x: X, y: Y | F
all x: X | all y: Y | F
但这两者并不等价:
one x: X, y: Y | F
one x: X | one y: Y | F
为什么后两者不等价?
我通过具体的例子学得最好,所以让我们举一个具体的例子。
上周我乘船去了阿拉斯加。晚餐时,我和另外五个人坐在一起。其中一对夫妇(杰森和丹妮丝)正在庆祝他们的第 25 个(银)结婚纪念日。
我创建了餐桌旁人的合金模型。该模型指定有一对 m: man, w: women 夫妇,其中 m 的妻子是 w,w 的丈夫是 m,m 和 w 正在庆祝银婚:
one m: Man, w: Woman |
m.wife = w and
w.husband = m and
m.anniversary = Silver and
w.anniversary = Silver
Alloy Analyzer 生成的实例符合我的预期。
然后我修改了表达式以使用嵌套表达式:
one m: Man |
one w: Woman |
m.wife = w and
w.husband = m and
m.anniversary = Silver and
w.anniversary = Silver
Alloy Analyzer 生成了相同的实例!
接下来,我写了一个断言,断言两个版本是等价的:
Version1 iff Version2
合金分析仪返回:未找到反例!
下面是我的模型。为什么这两个版本是等价的?我可以对模型进行一些小调整以显示嵌套版本和非嵌套版本之间的区别吗?
阿拉斯加游轮上的罗杰餐桌合金模型
abstract sig Man {
wife: lone Woman,
anniversary: lone Anniversary
}
one sig Roger extends Man {}
one sig Jason extends Man {}
abstract sig Woman {
husband: lone Man,
anniversary: lone Anniversary
}
one sig Faye extends Woman {}
one sig Nina extends Woman {}
one sig Claudia extends Woman {}
one sig Denise extends Woman {}
abstract sig Anniversary {}
one sig Silver extends Anniversary {}
pred v1_One_couple_celebrating_25th_wedding_anniversary {
one m: Man, w: Woman | m.wife = w and w.husband = m and
m.anniversary = Silver and w.anniversary = Silver }
pred v2_One_couple_celebrating_25th_wedding_anniversary {
one m: Man |
one w: Woman |
m.wife = w and w.husband = m and
m.anniversary = Silver and w.anniversary = Silver }
assert Both_versions_are_identical {
v1_One_couple_celebrating_25th_wedding_anniversary
iff
v2_One_couple_celebrating_25th_wedding_anniversary
}
check Both_versions_are_identical
【问题讨论】:
标签: alloy