更好的表达方式&x201C;正好一次”;在CBMC中

更好的表达方式&x201C;正好一次”;在CBMC中,c,model-checking,sat,cbmc,C,Model Checking,Sat,Cbmc,我正在努力想出一个更好的解决方案,在CBMC(C有界模型检查器)中声明“精确一次”属性。我的意思是,一行中只有一个元素位置的值应该是1(或者可以检查为布尔真的任何正数),其余的都必须是零 对于M=4 对于(i=0;i如何计算真值的数量,然后检查有多少: for (i = 0; i < M; i++) { int n_true = 0; int j; for (j = 0; j < M; j++) { n_true += (update[i][

我正在努力想出一个更好的解决方案,在CBMC(C有界模型检查器)中声明“精确一次”属性。我的意思是,一行中只有一个元素位置的值应该是1(或者可以检查为布尔真的任何正数),其余的都必须是零

对于M=4

对于(i=0;i如何计算真值的数量,然后检查有多少:

for (i = 0; i < M; i++) {
    int n_true = 0;
    int j;

    for (j = 0; j < M; j++) {
        n_true += (update[i][j] ? 1 : 0);
    }

    __CPROVER_assume(n_true == 1);
}
(i=0;i{ int n_true=0; int j; 对于(j=0;j
非常感谢:->John。从同一个想法开始。但不知怎么的,这不起作用,这就是为什么使用完整枚举。哦,天哪,我使用的是假设而不是假设,这就是全部问题所在。
for(i=0;i<M;i++){
   __CPROVER_assume( (update[i][0]) ?  ( !(update[i][1]) && !(update[i][2])  && !(update[i][3]) && (update[i][4]) && !(update[i][5])  && !(update[i][6]) && !(update[i][7]) )  :
           ((update[i][1]) ?  (!(update[i][2])  && !(update[i][3]) && !(update[i][4]) && !(update[i][5])  && !(update[i][6]) && !(update[i][7]) ) :
             ((update[i][2]) ? ((!update[i][3]) && !(update[i][4]) && !(update[i][5])  && !(update[i][6]) && !(update[i][7]))  :
                   ((update[i][3]) ? (!(update[i][4]) && !(update[i][5])  && !(update[i][6]) && !(update[i][7]))  : 
                   ((update[i][4]) ? (!(update[i][5])  && !(update[i][6]) && !(update[i][7])) : 
                      ((update[i][5]) ? (!(update[i][6]) && !(update[i][7])) :  
                         ((update[i][6]) ? !(update[i][7]) : (update[i][7])))))))) ;
}
for (i = 0; i < M; i++) {
    int n_true = 0;
    int j;

    for (j = 0; j < M; j++) {
        n_true += (update[i][j] ? 1 : 0);
    }

    __CPROVER_assume(n_true == 1);
}