different(Xs, Ys) :- member(X, Xs), non_member(X, Ys). different(Xs, Ys) :- member(Y, Ys), non_member(Y, Xs).
While this definition using member/2
and non_member/2
is almost1 perfect from a declarative viewpoint, it produces redundant solutions for certain queries and leaves choice points all around.
What is a definition that improves upon this (in a pure manner probably using if_/3
and (=)/3
) such that exactly the same set of solutions is described by different/2
but is determinate at least for ground queries (thus does not leave any useless choice points open) and omits (if possible) any redundant answer?
1 Actually, different([a|nonlist],[]), different([],[b|nonlist])
succeeds. It could equally fail. So a solution that fails for both is fine (maybe even finer).
Determination relates properties that are more or less specific, relative to each other. For example, red is a determinate of color; scarlet is a determinate of red.
Aristotle seems to have seen nothing more to existence than essence; there is not a space between an articulation of what a thing is and that thing's existing. Saint Thomas Aquinas, on the other hand, famously distinguished a thing's essence from its existence.
A thing is determinate when it is particularly designated or physically segregated from all others of the same class. (Art. 1460) It is determinate or specific if it is distinct from all others and can individually be classified or determined. From the word itself determinate meaning can be determined from all others.
Essence and Existence. A general notion of essence is the following: essence is the definable nature of the thing that exists. Quite generally then, the essence of a thing is signified by its definition. The immediate question then is how the essence of a thing relates to its existence.
First try!
The following code is based on the meta-predicates tfilter/3
and tpartition/4
, the monotone if-then-else control construct if_/3
, the reified unary logical connective not_t/3
, and the reified term equality predicate (=)/3
:
different([],[_|_]). different([X|Xs0],Ys0) :- tpartition(=(X),Ys0,Es,Ys1), if_(Es=[], true, (tfilter(not_t(=(X)),Xs0,Xs1),different(Xs1,Ys1))).
Sample query:
?- different([A,B],[X,Y]). A=Y , dif(B,Y), X=Y ; A=X , B=X , dif(X,Y) ; A=X , dif(B,X), dif(B,Y), dif(X,Y) ; A=Y , B=Y , dif(X,Y) ; A=Y , dif(B,X), dif(B,Y), dif(X,Y) ; dif(A,X), dif(A,Y).
Let's observe determinism when working with ground data:
?- different([5,4],[1,2]). true.
The above approach feels like a step in the right direction... But, as-is, I wouldn't call it perfect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With