anni
anni

Reputation: 1463

GNU Prolog : assert that list is ordered based on another list

I have two lists of integers, Xs, and Ys. I want to assert the following using GNU :

For i,j such that Xs[i]=Xs[j], i < j implies Ys[i]<Ys[j].

Any help would be appreciated!

Note : such an assertion would be possible since Ys is made up of integers that are all different.

Upvotes: 1

Views: 67

Answers (1)

rajashekar
rajashekar

Reputation: 3753

neg_ass(Xs, Ys) :-
    nth0(I, Xs, X),
    nth0(J, Xs, X),
    I < J,
    nth0(I, Ys, YI),
    nth0(J, Ys, YJ),
    YI >= YJ.
    
assertion(Xs, Ys) :-
   \+neg_ass(Xs, Ys).

Upvotes: 3

Related Questions