# "Steadfast" comparison of terms?

**URL:** <https://swi-prolog.discourse.group/t/steadfast-comparison-of-terms/4560>\
**Category:** Predicate\
**Tags:** discussion\
**Created:** [October 14, 2021, 11:42pm UTC](https://swi-prolog.discourse.group/t/steadfast-comparison-of-terms/4560 "2021-10-14T23:42:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [October 14, 2021, 11:42pm UTC](https://swi-prolog.discourse.group/t/steadfast-comparison-of-terms/4560/1 "2021-10-14T23:42:08Z")

</div>

Is there a way of comparing terms that is “steadfast”, in the sense that there doesn’t exist an instantiation of any of the variables that will change the result. For example:

```prolog
X @< Y % not steadfast if X=2,Y=1
p(X) @< p(Y) % not steadfast if X=2,Y=1
p(X) @< p(2) % not steadfast if X=3
p(X) @< q(Y) % steadfast

```

I _think_ that this will do it, raising an assertion error if the comparison isn’t steadfast (and similarly for (@\<)/2 et al; am I correct?

```prolog
steadfast_compare(Order, Term1, Term2) :-
    compare(Order, Term1, Term2),
    ( Order = '='
    -> true
    ; assertion( ?=(Term1,Term2) )
    ).

```
