在谓词中使用域表达式

时间:2015-11-30 06:22:13

标签: alloy

我正在尝试编写模块化谓词,如下所示,

pred total[rel:univ->univ] {
 all disj n, n': (~rel).univ | n in n'.rel or n' in n.rel
}

当我尝试使用

中的关系时,这不起作用
sig Node {
 order: set Node
}

fact {
 total[order]
}

然而我发现我必须指定n,n'的域。明确如下。

pred total[rel:univ->univ, domain: set univ] {
 all disj n, n': domain | n in n'.rel or n' in n.rel
}

fact {
  total[order, Node]
}

有没有办法不指定域并自动推断?

由于 维诺德

1 个答案:

答案 0 :(得分:2)

是的,有可能。

你实际上在第一次尝试时差不多了。 蒂尔达实际上太多了。如果你想获得关系域中的元素集,你可以在许多不同的选择中写出:

  • rel.univ
  • 大学。〜相对

     pred total[rel:univ->univ] {
        all n, n': rel.univ | n in n'.rel or n' in n.rel
     }
    

因此会做得很好

修改 如果你想在你的总谓词中,作为参数给出的关系的域由给定签名的所有原子组成,而不在总谓词中指定所述签名本身以保持通用,那么一种做法是制作一种新的谓词:

pred totalDomain(domain:set univ){
     domain= Node ||
     domain= X ||
     ... // other possible domains

}

允许强制执行,而不指定域所给出的关系是" total"在某种意义上它由现有签名的所有原子组成。

您将拥有:

     pred total[rel:univ->univ] {
        let domain=rel.univ{
           totalDomain[domain]
           all n, n': rel.univ | n in n'.rel or n' in n.rel
        }
     }