158
dest(ID,Where):-operation(ID,move(_,_,Where)),!.
dest(ID,Where):-operation(ID,copy(_,_,Where)),!.
dest_star(ID,Where):-dest(ID,Where).
dest_star(ID,Where):-dest(ID,address([I|_],Index)),dest_star(I,
Where).
%ThefollowingdefinestheorderingonPalimpsestaddresses.The
orderingiswell-
%definedforthelegaladdresses,asupersetoftheaddressesthat
wouldactually
%appearinaP-sequence.
%TheseclausescorresponddirectlywiththedefinitionsinChapter4.
less(address([],0),X):-X\=address([],0).
less(X,address([I|_],_)):-dest_star(I,S),S=X.
less(address([I1],Index1),address([I1],Index2)):-Index1<Index2,
!.
less(A,B):-
first_change_of(A,C1),
first_change_of(B,C2),
C1\=C2,
dest_llb(A,B,D1,D2),less(D1,D2),!.
less(address([I|T1],X1),address([I|T2],X2)):-
less(address(T1,X1),address(T2,X2)),!.
%less_eq/2isthereflexiveclosureofless/2.
less_eq(X,X):-!.
less_eq(X,Y):-less(X,Y).
%Calculatethecausallowerboundfortwoinsertions,sothattheycan
becompared.
%Firstwecalculatethechainofchangesalongourdestinationpath.
destinations(X,[X|T]):-
dest(X,address([I|_],_)),!,
destinations(I,T).
destinations(X,[X]):-
not(dest(X,address([I|_],_))),
!.
dest(ID,Where):-operation(ID,move(_,_,Where)),!.
dest(ID,Where):-operation(ID,copy(_,_,Where)),!.
dest_star(ID,Where):-dest(ID,Where).
dest_star(ID,Where):-dest(ID,address([I|_],Index)),dest_star(I,
Where).
%ThefollowingdefinestheorderingonPalimpsestaddresses.The
orderingiswell-
%definedforthelegaladdresses,asupersetoftheaddressesthat
wouldactually
%appearinaP-sequence.
%TheseclausescorresponddirectlywiththedefinitionsinChapter4.
less(address([],0),X):-X\=address([],0).
less(X,address([I|_],_)):-dest_star(I,S),S=X.
less(address([I1],Index1),address([I1],Index2)):-Index1<Index2,
!.
less(A,B):-
first_change_of(A,C1),
first_change_of(B,C2),
C1\=C2,
dest_llb(A,B,D1,D2),less(D1,D2),!.
less(address([I|T1],X1),address([I|T2],X2)):-
less(address(T1,X1),address(T2,X2)),!.
%less_eq/2isthereflexiveclosureofless/2.
less_eq(X,X):-!.
less_eq(X,Y):-less(X,Y).
%Calculatethecausallowerboundfortwoinsertions,sothattheycan
becompared.
%Firstwecalculatethechainofchangesalongourdestinationpath.
destinations(X,[X|T]):-
dest(X,address([I|_],_)),!,
destinations(I,T).
destinations(X,[X]):-
not(dest(X,address([I|_],_))),
!.