156
F F F F iii ig g g gu u u ur r r re e e e AAAA....7777:::: LLLLiiiissssttttiiiinnnngggg ooooffff PPPPrrrroooolllloooogggg tttteeeesssstttt pppprrrrooooggggrrrraaaammmm
%thesepredicatestestthetypeofanoperation,givenitsID.
is_insert(ID):-operation(ID,insert(_,_)).
is_move(ID):-operation(ID,move(_,_,_)).
is_copy(ID):-operation(ID,copy(_,_,_)).
is_delete(ID):-operation(ID,delete(_,_)).
first_change_of(address([X|_],_),X).
%Herewedefinethenotionof"legal"addresses,onesthatmeetthe
%syntacticandoperationtyperestrictionsonthelegalPalimpsest
%addresses.Someoftheserestrictionsactuallycarryimportant
%semanticweight.Thepossibilityofcyclicstructureswhere
%dataisrepeatedlymovedispreventedbythefactthat
%addressesarefiniteinsizeandthatnochange-IDcanappear
%morethanonceinagivenaddress.
legal(address([],0)).
legal(address([I],X)):-valid_index(I,X).
legal(address([I|T],X)):-
operation(I,_),
not(is_insert(I)),
not(is_delete(I)),
legal(address(T,X)).
%Thispredicatetests(andenumerates)thevalidindiceswithinan
insertion.
%Thesearethepositionsofgapsinthesequencethattheinsertion
addstothe
%P-sequenceinquestion.
valid_index(I,Index):-
operation(I,insert(_,SEQ)),
append(A,B,SEQ),
length(A,Index).
%Thispredicatereturnsalegaladdressforagivensetofchanges.On
failureit
%willproduceanotheruntiltheentirelisthasbeenenumerated.
legal_address_for(LIST,A):-
permutation_dropping(LIST,P),
A=address(P,Index),
legal(A).
F F F F iii ig g g gu u u ur r r re e e e AAAA....7777:::: LLLLiiiissssttttiiiinnnngggg ooooffff PPPPrrrroooolllloooogggg tttteeeesssstttt pppprrrrooooggggrrrraaaammmm
%thesepredicatestestthetypeofanoperation,givenitsID.
is_insert(ID):-operation(ID,insert(_,_)).
is_move(ID):-operation(ID,move(_,_,_)).
is_copy(ID):-operation(ID,copy(_,_,_)).
is_delete(ID):-operation(ID,delete(_,_)).
first_change_of(address([X|_],_),X).
%Herewedefinethenotionof"legal"addresses,onesthatmeetthe
%syntacticandoperationtyperestrictionsonthelegalPalimpsest
%addresses.Someoftheserestrictionsactuallycarryimportant
%semanticweight.Thepossibilityofcyclicstructureswhere
%dataisrepeatedlymovedispreventedbythefactthat
%addressesarefiniteinsizeandthatnochange-IDcanappear
%morethanonceinagivenaddress.
legal(address([],0)).
legal(address([I],X)):-valid_index(I,X).
legal(address([I|T],X)):-
operation(I,_),
not(is_insert(I)),
not(is_delete(I)),
legal(address(T,X)).
%Thispredicatetests(andenumerates)thevalidindiceswithinan
insertion.
%Thesearethepositionsofgapsinthesequencethattheinsertion
addstothe
%P-sequenceinquestion.
valid_index(I,Index):-
operation(I,insert(_,SEQ)),
append(A,B,SEQ),
length(A,Index).
%Thispredicatereturnsalegaladdressforagivensetofchanges.On
failureit
%willproduceanotheruntiltheentirelisthasbeenenumerated.
legal_address_for(LIST,A):-
permutation_dropping(LIST,P),
A=address(P,Index),
legal(A).