[英]Alloy:How to understand the counterexample in the Alloy demo?
出於好奇,我寫了一個關於“斷言”的奇怪合金演示。
假設有一個“程序”,“程序”有 2 個“品種”,每個“品種”都有一個“數據”集中的“值”。
然后我還設置了一個“事實”,即“Variety”的所有“Value”都是“data1”。
最后,我設置了一個“斷言”,即對於所有“程序”,“程序”中“品種”的所有“價值”都是“data1”。
我認為“斷言”滿足“事實”,但是當我檢查“斷言”時,它給出了一個反例,我對此無法理解,為什么它有反例?
代碼如下所示:
enum Data{data1,data2}
sig Program{
Var1:Variable,
Var2:Variable
}
sig Variable{
Value:Data
}
fact{
all v:Variable{
v.Value=data1
}
}
assert test{
all p:Program{
all v:(Program->Variable){
p.v.Value=data1
}
}
}
反例如下:
我對您的示例有些困惑,因為似乎沒有使用 var1 和 var2 字段。 但是你得到一個反例的原因可能是因為 v 可以為空,在這種情況下pvValue
評估為空關系,而data1
評估為 singleton,所以它們不相等。
我的問題有兩個錯誤,我修改了代碼,現在是。
enum Data{data1,data2}
sig Program{
Var1:Variable,
Var2:Variable
}
sig Variable{
Value:Data
}
fact{
all p:Program{
//In theory, there should be "all v:(Program->Variable)", but Alloy does not support HOL.
//all v:(Program->Variable){
p.Var1.Value=data1
p.Var2.Value=data1
// }
}
}
assert test{
all p:Program{
p.Var1.Value=data1
p.Var2.Value=data2
// And here is another mistake, Var1 and Var2 is only the subset of "all v:(Program->Variable)"
// all v:(Program->Variable){
// p.v.Value=data1
// }
}
}
check test for 10 but 1 Program
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.