问题
Does TLA+ have an xor operator defined as part of the language itself, or do I have to define my own?
回答1:
Under the assumption that A \in BOOLEAN /\ B \in BOOLEAN
, what is known in propositional logic as "XOR" is inequality:
A # B
which under the same assumption is equivalent to ~ (A <=> B)
. When A, B
take non-Boolean values, these two formulas are not necessarily equivalent. The operator <=>
means the following
/\ A \in BOOLEAN
/\ B \in BOOLEAN
/\ A = B
So
(~ (A <=> B)) <=> \/ ~ A \in BOOLEAN
\/ ~ B \in BOOLEAN
\/ ~ (A = B)
Thus, if the first two disjuncts are false, then <=>
and =
are equivalent. Otherwise it can be the case that
/\ A \notin BOOLEAN
/\ A = B
which could satisfy A <=> B
. See also p.10 and Sec. 16.1.3 of the TLA+ book. The formula
(A \/ B) /\ ~ (A /\ B)
is meaningful also for non-Boolean values of the identifiers A
and B
, because TLA+ is untyped. So
(15 \/ "a") /\ ~ (15 /\ "a")
is a possible value. As far as I know, the language doesn't specify whether this formula has the same value as
15 # "a"
来源:https://stackoverflow.com/questions/46698480/is-there-an-xor-exclusive-or-infix-operator-in-tla