简体   繁体   English

Alloy:如何理解Alloy demo中的反例?

[英]Alloy:How to understand the counterexample in the Alloy demo?

I write a strange Alloy demo about "assert" out of curiosity.出于好奇,我写了一个关于“断言”的奇怪合金演示。

Assume there is a "Program", the "Program" has 2 "Varieties", and each "Variety" has a "Value" from "Data" set.假设有一个“程序”,“程序”有 2 个“品种”,每个“品种”都有一个“数据”集中的“值”。

Then I also set a "fact" that all of the "Value" of the "Variety" are "data1".然后我还设置了一个“事实”,即“Variety”的所有“Value”都是“data1”。

Finally, I set an "assert" that for all "Program", all of "Value" of the "Variety" in the "Program" are "data1".最后,我设置了一个“断言”,即对于所有“程序”,“程序”中“品种”的所有“价值”都是“data1”。

I think the "assert" satisfies the "fact", however when I check the "assert", it gives a counterexample, I cannot understand about this, why it has the counterexample?我认为“断言”满足“事实”,但是当我检查“断言”时,它给出了一个反例,我对此无法理解,为什么它有反例?

The code appears as follows:代码如下所示:

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
        }
    }
}

The counterexample is as follows:反例如下:

在此处输入图像描述

在此处输入图像描述

I'm a bit confused about your example because the var1 and var2 fields don't seem to be used.我对您的示例有些困惑,因为似乎没有使用 var1 和 var2 字段。 But the reason you're getting a counterexample is probably because v can be empty, in which case pvValue evaluates to the empty relation, and data1 evaluates to a singleton, so they're not equal.但是你得到一个反例的原因可能是因为 v 可以为空,在这种情况下pvValue评估为空关系,而data1评估为 singleton,所以它们不相等。

There are two mistakes in my question, I modify the code, and it is right now.我的问题有两个错误,我修改了代码,现在是。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM