From a-doug@microsoft.com  Fri Jan  7 15:07:01 2000
Received: from mail1.microsoft.com (mail1.microsoft.com [131.107.3.125])
	by swi.psy.uva.nl (8.9.3/8.9.3) with SMTP id PAA10355
	for <prolog@swi.psy.uva.nl>; Fri, 7 Jan 2000 15:07:00 +0100 (MET)
Received: from 157.54.9.101 by mail1.microsoft.com (InterScan E-Mail VirusWall NT); Fri, 07 Jan 2000 06:06:33 -0800 (Pacific Standard Time)
Received: by INET-IMC-01 with Internet Mail Service (5.5.2650.21)
	id <CM1M9FW7>; Fri, 7 Jan 2000 06:06:33 -0800
Message-ID: <E713F2760348D211A9B600805F6FA1AB03559909@RED-MSG-09.itg-messaging.redmond.corp.microsoft.com>
From: "Douglas Miles (Volt Computer)" <a-doug@microsoft.com>
To: "'prolog@swi.psy.uva.nl'" <prolog@swi.psy.uva.nl>
Subject: RE: I am having trouble writing replace/4 
Date: Fri, 7 Jan 2000 06:06:29 -0800 
X-Mailer: Internet Mail Service (5.5.2650.21)

Thank you so we now have these they both work very well.  
The 2 are logically equivalent
I guess the difference in the *-> vs. separated clauses?

But both do what they are needed for :).. my original produced some real
funny results in a machine dissembler I am building.

I'll share the complete code for it when I am done, if you guys are
interested.
It basically takes 2 Lists of Machine Code (actually Lists of Anything) that
are logically similar.. It unifies them as much as it can.  Then presents
you with a difference between the lists.. It presents a few prolog rules
that would have been required in total unification and why from rules
learned before that the structures are possibly equivalent.

for example..
?-make_new_rule([my,dog,has,fleas],[my,cat,has,worms],Rule).

Rule=new_rule(
	from_to(MY,dog,HAS,fleas],[MY,cat,HAS,worms]),
	varlist(['MY'=my,'HAS'=has]),
	required_prolog((
		mem('MY',MY),
		mem('HAS',HAS)
		(related(dog,cat);related(cat,dog)),
		(related(fleas,worms);related(worms,fleas))
		)),
	asserted((mem('MY',my),mem('HAS',has)))
	protos([[dog,fleas],[cat,worms]]),
	final(
		rule([MY,_A,HAS,_B],[MY,_C,HAS,_D],
	
(mem('MY',MY),mem('HAS',HAS),related(_A,_B),related(_C,_D))
		)
	)

Well you can see the basic concept.. The lists are not of course always the
same length and there are going to be _several_ "required_prolog" outputs ..

related/2 is the last resort 'cheat' it will come up with.
mem/2 is all that can be 'known thru basic unification' or 'told to be true'

premuted/2, both_sibs/2, etc..

The goal is it will be fed similar lists until it has a basic rules set and
that it can be left to its own devices for future conversions.


Thanks again Pascal, Rinke and Marcos :) 	
	Douglas Miles a-doug@microsoft.com
	<goofy-ms.gif>

/*   Pascal Vaillant [mailto:Pascal.Vaillant@rz.hu-berlin.de] */

replaceList([],[],NothingToDo,NothingToDo).

replaceList([HeadBefore|TailBefore],[HeadAfter|TailAfter],Start,End) :-
  replace(HeadBefore,HeadAfter,Start,Middle),
  replaceList(TailBefore,TailAfter,Middle,End).

replace(_,_,[],[]).

replace(A,B,[C|L],[D|R]) :-
  ((A==C) *->
   D=B ;
   D=C),
  replace(A,B,L,R).


/*    Rinke Hoekstra [mailto:rhoekstr@wins.uva.nl]  */

replace_list([],[],List,List).
replace_list([HReplacant|TReplacant],[HReplacer|TReplacer],List,NewList):-
 	replace(HReplacant,HReplacer,List,IList),
 	replace_list(TReplacant,TReplacer,IList,NewList).

replace(_,_,[],[]).
replace(HReplacant1,HReplacer,[HReplacant2|Tail],[HReplacer|NewTail]):-
	HReplacant1 == HReplacant2,
 	replace(HReplacant1,HReplacer,Tail,NewTail).
replace(HReplacant,HReplacer,[Head|Tail],[Head|NewTail]):-
 	replace(HReplacant,HReplacer,Tail,NewTail).


/*  And thank you as well Marcos :) [mailto:marcos@mind.pt]   */

replaceList(_,_,[],[]):-!.
replaceList(L1,L2,[X|RestL],[X2|ResulL]):-!,
   replace(L1,L2,X,X2),
   replaceList(L1,L2,RestL,ResulL).


replace([], [], X, X).
replace([X|_], [X2|_], X, X2):-!.
replace([_|L], [_|L2], X, X2):-
	replace(L, L2, X, X2).

