# Undecidable order (some cyclic terms)

**URL:** https://swi-prolog.discourse.group/t/undecidable-order-some-cyclic-terms/9833
**Category:** Request For Comments
**Created:** [September 23, 2026, 12:56pm UTC](https://swi-prolog.discourse.group/t/undecidable-order-some-cyclic-terms/9833 "2026-09-23T12:56:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [September 23, 2026, 12:56pm UTC](https://swi-prolog.discourse.group/t/undecidable-order-some-cyclic-terms/9833/1 "2026-09-23T12:56:20Z")

</div>

A reported bug on standard order for cyclic terms (#1529) made it free to detect cyclic terms that have no defined order. As a result, SWI-Prolog now has a flag `incomparable` that can be set to `arbitrary` (default, old behaviour, i.e., different representation leads to different results and transitivity is not guaranteed) and `error`, raising `representation_error(standard_order(Sub1, Sub2))`, where the culprits are the cycles that cause the problem. So, now we get

```prolog
102 ?- set_prolog_flag(incomparable, error).
true.

103 ?- X=f(X,0),Y=f(Y,1), sort([X,Y], L).
ERROR: Cyclic terms have no standard order: @(S_1,[S_1=f(S_1,0)]) and @(S_1,[S_1=f(S_1,1)])
ERROR: In:
ERROR: [16] sort([f(...,0),...],_280)
ERROR: [14] toplevel_call(user:user: ...) at /home/jan/src/swipl-devel/build/home/boot/toplevel.pl:1678
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

```

In addition, the new partial\_compare/3 gives (regardless of the flag):

```prolog
109 ?- X=f(X,0),Y=f(Y,1), partial_compare(Diff, X, Y).
X = f(X, 0),
Y = f(Y, 1),
Diff = incomparable(f(X, 0), f(Y, 1)).

```
