2

Lets assume there is pure_2 Prolog with dif/2 and pure_1 Prolog without dif/2. Can we realize Peano apartness for values, i.e. Peano numbers, without using dif/2? Thus lets assume we have Peano apartness like this in pure_2 Prolog:

/* pure_2 Prolog */
neq(X, Y) :- dif(X, Y).

Can we replace neq(X,Y) by a more pure definition, namely from pure_1 Prolog that doesn't use dif/2? So that we have a terminating neq/2 predicate that can decide inequality for Peano numbers? So what would be its definition?

/* pure_1 Prolog */
neq(X, Y) :- ??

2 Answers2

3

Using less from this comment:

less(0, s(_)).
less(s(X), s(Y)) :- less(X, Y).

neq(X, Y) :- less(X, Y); less(Y, X).
MWB
  • 10,855
  • 6
  • 41
  • 80
3

I had something else in mind, which is derived from two of the Peano Axioms, which is also part of Robinson Arithmetic. The first axiom is already a Horn clause talking about apartness:

   ∀x(0 ≠ S(x)) 

   ∀x∀y(S(x) = S(y) ⇒ x = y)

Applying contraposition to the second axiom gives.
The axiom is now a Horn clause talking about apartness:

   ∀x∀y(x ≠ y ⇒ S(x) ≠ S(y))

Now we have everything to write some Prolog code.
Adding some symmetry we get:

neq(0, s(_)).
neq(s(_), 0).
neq(s(X), s(Y)) :- neq(X, Y).

Here are some example queries. Whether the predicate leaves a choice
point depends on the Prolog system. I get:

SWI-Prolog 8.3.15 (some choice point):

?- neq(s(s(0)), s(s(0))).
false.

?- neq(s(s(0)), s(0)).
true ;
false.

Jekejeke Prolog 1.4.6 (no choice point):

?- neq(s(s(0)), s(s(0))).
No

?- neq(s(s(0)), s(0)).
Yes
  • Your prolog program is basically the same as the one from the accepted answer, sans trivial transformation. – gusbro Dec 24 '20 at 00:37
  • 2
    @gusbro: Trivial means here belonging to the [trivium](https://en.wikipedia.org/wiki/Trivium). While it has the same termination property, it is superior w.r.t existential termination. `?- neq(X,Y), X = s(0), Y = 0.` finds a solution whereas the other answer just loops away. – false Dec 24 '20 at 08:49
  • @false: You are right, this program does not loop in your example as with the accepted answer. And I meant "trivial transformation" as in "simple transformation"; now I see it does not behave exactly the same. – gusbro Dec 27 '20 at 21:57
  • For the reasons @false and gusbro discuss, this should instead be the accepted solution. – Jason Hemann Apr 30 '22 at 21:47