Re: how to rename variables?



On Aug 25, 5:43 am, Giovanni Gherdovich
<gherdov...@xxxxxxxxxxxxxxxxxxxxxx> wrote:
Dear Mr. Demoen,

Try copy_term/2.

Yes, this is the right predicate;
thankyou.

| ?- copy_term(X+Y, OutputTerm).
|
| X = _G180
| Y = _G181
| OutputTerm = _G272+_G273 ;
|
| No
| ?- copy_term(f(X,X), OutputTerm).
|
| X = _G180
| OutputTerm = f(_G257, _G257) ;
|
| No

Regards,
Giovanni

Hi, Giovanni:


I believe you have noticed that, to get the result
described in your original post, where the X in
the term X+Y first listed is not bound to the same
new variable as the X in the term f(X,X), you will
need to apply copy_term/2 to each entry in the list
of terms.

| ?- copy_term([X+Y,f(X,g(X))],OutTerm).
|
| X = _G187
| Y = _G188
| OutTerm = [_G300+_G301, f(_G300, g(_G300))] ;

As the above illustrates, passing the entire list
at once to copy_term creates a coherent mapping of
the variables, X going from _G187 to _G300 in all
appearances, while your example had the X in the
first term coming "unglued" from the X's in the
second term of the list.

regards, chip

.