# Is the dot operator only left-associative, not just associative?

**URL:** <https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513>\
**Category:** Questions\
**Created:** [February 25, 2025, 1:02pm UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513 "2025-02-25T13:02:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Alejandro](https://alloytools.discourse.group/u/Alejandro)\
**Post date:** [February 25, 2025, 1:02pm UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513/1 "2025-02-25T13:02:41Z")

</div>

From the [alloy spec](https://alloytools.org/spec.html#precedence-and-associativity):

> All binary operators associate to the left, with the exception of implication and sequence, which associate to the right, and of binary temporal connectives which are not associative.

Is the dot operator only left-associative, not both left- and right-associative, which is just associative?

When is (a.b).c != a.(b.c)?

---

<div class="post-metadata">

**Author:** ![peter.kriens](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/peter.kriens/32/3_2.png) [@peter.kriens](https://alloytools.discourse.group/u/peter.kriens)\
**Post date:** [February 25, 2025, 1:51pm UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513/2 "2025-02-25T13:51:10Z")

</div>

```auto
sig A, B, C, D {}

pred whenNotAssociative[a : A->B, b : B->C, c : C->D] { 
	a.(b.c) != (a.b).c 
}

run whenNotAssociative

```

---

<div class="post-metadata">

**Author:** ![Alejandro](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Alejandro](https://alloytools.discourse.group/u/Alejandro)\
**Post date:** [February 25, 2025, 2:01pm UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513/3 "2025-02-25T14:01:32Z")

</div>

This is a cool answer, thanks.

---

<div class="post-metadata">

**Author:** ![grayswandyr](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/grayswandyr/32/17_2.png) [@grayswandyr](https://alloytools.discourse.group/u/grayswandyr)\
**Post date:** [February 25, 2025, 2:03pm UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513/4 "2025-02-25T14:03:44Z")

</div>

@peter.kriens’ command yields no counterexample, which could make think dot join is associative _while it’s not._

Here is the explanation by @DanielJackson in his book:

> If the arguments are binary relations, it is [associative]. But in general, the expressions `(a.b).c` and `a.(b.c)` are not equivalent. Moreover, one may be ill-formed and the other well-formed. Because of the dropped column, the arity of a join is always one less than the sum of the arities of its arguments. If `s` and `t` are unary, and `r` is ternary, for example, the expression `t.r` will be binary, and `s.(t.r)` will be unary. The expression `s.t`, however, would have zero arity, and is thus illegal, so `(s.t).r` is likewise illegal, and is certainly not equivalent to `s.(t.r)`.

---

<div class="post-metadata">

**Author:** ![peter.kriens](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/peter.kriens/32/3_2.png) [@peter.kriens](https://alloytools.discourse.group/u/peter.kriens)\
**Post date:** [February 25, 2025, 2:17pm UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513/5 "2025-02-25T14:17:50Z")

</div>

David is right. I should have reacted to my suspicion when I realized I need to specify the cardinality of the type. Sadly Alloy has no `Any` type which could also vary the cardinality.

Sorry.

---

<div class="post-metadata">

**Author:** ![dkasak](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/dkasak/32/172_2.png) [@dkasak](https://alloytools.discourse.group/u/dkasak)\
**Post date:** [February 25, 2025, 11:12pm UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513/6 "2025-02-25T23:12:08Z")

</div>

Incidentally, I just noticed this sentence of the book is incorrect:

> Because of the dropped column, the arity of a join is always one less than the sum of the arities of its arguments.

The arity of a join is _two_ less than the sum of the arities of its arguments, not one, because the join column disappears entirely.

The example immediately following that sentence gets it right though:

> If s and t are unary, and r is ternary, for example, the expression t.r will be binary, and s.(t.r) will be unary.

t is unary (1), r is ternary (3), so t.r is is binary (3+1-2 = 2).

---

<div class="post-metadata">

**Author:** ![grayswandyr](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/grayswandyr/32/17_2.png) [@grayswandyr](https://alloytools.discourse.group/u/grayswandyr)\
**Post date:** [February 26, 2025, 6:32am UTC](https://alloytools.discourse.group/t/is-the-dot-operator-only-left-associative-not-just-associative/513/7 "2025-02-26T06:32:23Z")

</div>

Indeed you’re right 👍
