Pure Prolog Peano Number Apartness

▼魔方 西西 提交于 2021-01-15 22:47:17

问题


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) :- ??

回答1:


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).



回答2:


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


来源:https://stackoverflow.com/questions/65427391/pure-prolog-peano-number-apartness

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!