Does SWI-Prolog do variable aliasing?

When issuing the following code at the prompt…

?- X is 3, Y is 3.

The following output appears:

X = Y, Y = 3.

I’d love a better understanding of what’s happening with that X=Y, and why it doesn’t say X=3. Is SWI-Prolog doing some kind of variable aliasing as an optimization?

Variable aliasing? No, because the variables are immutable.

Unification? Yes, Prolog uses syntactic unification

See this answer for more details.

What do you mean by “variable aliasing”?

SWI-Prolog could have also output X=3,Y=3 and that’s exactly equivalent to X=Y,Y=3 – there is no way that you can distinguish the two. It’s more compact to write it as X=Y if the result is some large complex term.

Put another way, X=Y means that there is no way to distinguish X and Y. These statements produce the same result:

X=Y, X=3.
X=Y, Y=3.
X=3, X=Y.
Y=X, 3=Y.

Thanks, that’s helpful. In the link to the other answer, I found this statement added some clarity for me:

[it] is generally not observable whether two terms are equal because they have been unified or simply because they happen to have the same value.

Again, thanks.