Skip to content

Commit 9c9c445

Browse files
committed
Rename operator IsASet to IsInjective (in TLA+ all things are sets).
1 parent 10b4f35 commit 9c9c445

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

SequencesExt.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ private SequencesExt() {
3838
// no-instantiation!
3939
}
4040

41-
public static BoolValue IsASet(final Value val) {
41+
public static BoolValue IsInjective(final Value val) {
4242
if (val instanceof TupleValue) {
43-
return isASetNonDestructive(((TupleValue) val).elems);
43+
return isInjectiveNonDestructive(((TupleValue) val).elems);
4444
} else {
4545
final Value conv = val.toTuple();
4646
if (conv == null) {
4747
throw new EvalException(EC.TLC_MODULE_ONE_ARGUMENT_ERROR,
4848
new String[] { "IsASet", "sequence", Values.ppr(val.toString()) });
4949
}
50-
return isASetDestructive(((TupleValue) conv).elems);
50+
return isInjectiveDestructive(((TupleValue) conv).elems);
5151
}
5252
}
5353

5454
// O(n log n) runtime and O(1) space.
55-
private static BoolValue isASetDestructive(final Value[] values) {
55+
private static BoolValue isInjectiveDestructive(final Value[] values) {
5656
Arrays.sort(values);
5757
for (int i = 1; i < values.length; i++) {
5858
if (values[i-1].equals(values[i])) {
@@ -66,7 +66,7 @@ private static BoolValue isASetDestructive(final Value[] values) {
6666
// space is good enough. Sorting values in-place is a no-go because it
6767
// would modify the TLA+ tuple. Elements can be any sub-type of Value, not
6868
// just IntValue.
69-
private static BoolValue isASetNonDestructive(final Value[] values) {
69+
private static BoolValue isInjectiveNonDestructive(final Value[] values) {
7070
for (int i = 0; i < values.length; i++) {
7171
for (int j = i + 1; j < values.length; j++) {
7272
if (values[i].equals(values[j])) {

SequencesExt.tla

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ ToSet(s) ==
1515
(*************************************************************************)
1616
{ s[i] : i \in 1..Len(s) }
1717

18-
IsASet(s) ==
18+
IsInjective(s) ==
1919
(*************************************************************************)
2020
(* TRUE iff the sequence s contains no duplicates where two elements *)
2121
(* a, b of s are defined to be duplicates iff a = b. In other words, *)
2222
(* Cardinality(ToSet(s)) = Len(s) *)
2323
(* *)
24-
(* This definition is overridden by TLC in the Java class *)
25-
(* tlc2.module.SequencesExt. The operator is overridden by the Java *)
26-
(* method with the same name. *)
24+
(* This definition is overridden by TLC in the Java class SequencesExt. *)
25+
(* The operator is overridden by the Java method with the same name. *)
2726
(*************************************************************************)
2827
\A i,j \in 1..Len(s): i # j => s[i] # s[j]
2928

SequencesExtTests.tla

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
------------------------- MODULE SequencesExtTests -------------------------
22
EXTENDS Sequences, SequencesExt, Naturals, TLC
33

4-
ASSUME(IsASet(<<>>))
5-
ASSUME(IsASet(<<1>>))
6-
ASSUME(IsASet(<<1,2,3>>))
7-
ASSUME(~IsASet(<<1,1>>))
8-
ASSUME(~IsASet(<<1,1,2,3>>))
4+
ASSUME(IsInjective(<<>>))
5+
ASSUME(IsInjective(<<1>>))
6+
ASSUME(IsInjective(<<1,2,3>>))
7+
ASSUME(~IsInjective(<<1,1>>))
8+
ASSUME(~IsInjective(<<1,1,2,3>>))
99

10-
ASSUME(IsASet([i \in 1..10 |-> i]))
11-
ASSUME(IsASet([i \in 1..10 |-> {i}]))
12-
ASSUME(IsASet([i \in 1..10 |-> {i}]))
13-
ASSUME(~IsASet([i \in 1..10 |-> {1,2,3}]))
10+
ASSUME(IsInjective([i \in 1..10 |-> i]))
11+
ASSUME(IsInjective([i \in 1..10 |-> {i}]))
12+
ASSUME(IsInjective([i \in 1..10 |-> {i}]))
13+
ASSUME(~IsInjective([i \in 1..10 |-> {1,2,3}]))
1414

1515
=============================================================================

0 commit comments

Comments
 (0)