简体   繁体   English

合金均等

[英]Equality in alloy

I've got an Alloy model which contains the following : 我有一个包含以下内容的Alloy模型:

abstract sig person{}

one sig john,Steve extends person  {Gender: man} 

sig man{}

fact {
  all name: person, Gender: man | 
      name.Gender = name.Gender => person =person}

How can I make equality between two signatures? 如何使两个签名相等?

It's not clear from your question what you want to do, and from your sample Alloy code it looks as if you may be suffering from some confusions. 从您的问题中尚不清楚您要做什么,并且从您的示例Alloy代码来看,您似乎似乎正遭受一些困惑。

First, the model you show uses the name Gender in two different ways, which is not illegal in itself but seems to suggest some confusion. 首先,您显示的模型以两种不同的方式使用名称Gender,这本身不是非法的,但似乎暗示了一些混淆。 (It certainly confuses the willies out of this reader.) (这肯定会使读者迷惑不解。)

In the declaration for the two singleton signatures john and Steve, Gender denotes two binary relations, one holding between the signature john and the signature man, the other holding between Steve and man. 在两个单例签名john和Steve的声明中,性别表示两个二进制关系,一个在签名john和签名的man之间持有,另一个在Steve和man之间持有。 To say the same thing in symbolic form, Gender denotes (a) some subset of john -> man, and (b) some subset of Steve -> man. 用符号形式说同样的事情,性别代表(a)john-> man的一些子集,和(b)Steve-> man的一些子集。

In the anonymous fact, however, Gender denotes a variable of type man. 但是,在匿名事实中,性别表示类型为man的变量。

Your model will be easier to understand if you find a way to rename one or the other of these. 如果您找到一种方法来重命名它们中的一个,则模型将更容易理解。 Since variable names in a quantified expression are arbitrary, your fact will mean the same thing if you reformulate it as 由于量化表达式中的变量名称是任意的,因此,如果将其重新格式化为

fact { all P : person, M : man | P.M = P.M => person = person }

If that's not what you meant to say, then you may have meant to say something like 如果这不是您要说的话,那么您可能想说些类似的话

fact { all P : person, M : man | 
    P.Gender = P.Gender => person = person 
}

Renaming the variable forces you to choose one meaning or the other. 重命名变量将迫使您选择一种含义或另一种含义。 This is a good thing. 这是一件好事。 (It is an unfortunate fact that neither formulation is actually satisfactory in Alloy. But let's deal with one problem at a time; getting rid of the double use of the name Gender is the first step.) (一个不幸的事实是,Alloy的配方都不令人满意。但是让我们一次处理一个问题;摆脱双重使用Gender是第一步。)

A second issue is that whichever formulation of the fact you meant, it almost certainly doesn't mean what you wanted it to mean. 第二个问题是无论您要表达的事实是什么,几乎可以肯定它并不意味着您要表达的意思。 Ignoring the specifics of the model for a moment, your fact takes the form 暂时忽略模型的细节,您的事实采用以下形式

fact { all V1 : sig1, V2 : sig2 | 
  Expression = Expression => sig1 = sig1
}

where Expression is either V1.V2 or V1.Relation, for some Relation defined in the model. 对于模型中定义的某些Relation,其中Expression为V1.V2或V1.Relation。 There are several things wrong here: 这里有几处错误:

  • V1.V2 is meaningless where V1 and V2 are both names of signatures or variables ranging over given signatures: the dot operator is meaningful only if one of its arguments is the name of a relation. V1.V2是无意义的,其中V1和V2都是签名的名称或在给定签名范围内的变量:点运算符仅在其参数之一是关系的名称时才有意义。

  • If any expression E is meaningful at all, then a Boolean expression of the form E = E (for example, person.Gender = person.Gender) is true regardless of what E means. 如果任何表达式E都是有意义的,则无论E意味着什么,形式为E = E的布尔表达式(例如person.Gender = person.Gender)都是正确的。 Anything denoted by E is naturally going to be equal to itself. 用E表示的任何事物自然都将等于其自身。 So the conditional might as well be written 所以有条件的话也可以写成

     1 = 1 => person = person 
  • For the same reason, person = person will always be true, regardless of the model: for any model instance the set of persons in the instance will be identical to the set of persons in the instance. 出于相同的原因,无论模型如何,person = person始终为真:对于任何模型实例,实例中的人员集合将与实例中的人员集合相同。 So the conditional will always be true, and the fact won't actually impose any constraint on instances of the model. 因此,条件将始终为真,并且事实实际上不会对模型实例施加任何约束。

It's not clear how best to help you move forward. 目前尚不清楚如何最好地帮助您前进。 Perhaps one way to start would be to ask yourself which of the following statements you are trying to capture in your model. 也许一种开始的方法是问自己要尝试在模型中捕获以下哪些语句。

  • There is a set of persons. 有一组人。
  • Some persons are males (have gender = 'man'). 有些人是男性(性别=“男人”)。 Others are not males. 其他不是男性。
  • John is a male individual. 约翰是男性。
  • Steve is a male individual. 史蒂夫是男性。
  • John and Steve are distinct individuals. 约翰和史蒂夫是不同的人。
  • If x and y are individuals with the same gender, then x and y are the same individual. 如果x和y是具有相同性别的个体,则x和y是相同的个体。 Ie no two individuals have the same gender. 即没有两个人具有相同的性别。

Note that these statements cannot all be true at the same time. 请注意,这些语句不能同时全部成立。 (If that's not obvious, you might do worse than try to figure out why. Alloy can be helpful in that effort.) (如果不是很明显,那么您可能比尝试找出原因做得更糟。Alloy在此方面可能会有所帮助。)

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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