Re: copy variables including their constraints

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Fri 02 May 2003 11:14:44 AM GMT
Message-ID: <3EB25324.D080899A@icparc.ic.ac.uk>
Ulrich Scholz wrote:
> 
> > > > If you can collect the constraints in that way, this is probably the
> > > > best solution. You might not need to list all individual constraints,
> > > > you just need one goal that sets them all up:
> > > >
> > > > ?-  setup_cstr(Vars),
> > > >     copy_term(Vars-setup_cstr(Vars), VarsCopy-GoalCopy),
> > > >     call(GoalCopy),
> > > >     ...
> > >
> > > Ah, that is a sneak way of unifying some but not all variables of a term.
> >
> > ??? You may be misunderstanding something.
> >
> 
> Yes, it seems as if I don't understand your code.  setup_cstr(Vars) is a
> clause that sets up the constraints on Vars (a list of Varialbles).  Why does
> copy_term(...) have setup_cstr(Vars) again?

Ok, that was unnecessarily complicated. I could just have written

 ?-  setup_cstr(Vars),
     copy_term(Vars, VarsCopy),
     setup_cstr(VarsCopy),
     ...


> 
> In my understanding,
> 
> copy_term(OrigTerm-VariablestoBeUnified, GoalTerm-ListOfUnifiers)
> 
> unfies the Variables in VariablesToBeUnified, which are Variables occuring in
> term OrigTerm, with the terms in ListOfUnifiers, eg

Nothing in VariablesToBeUnified gets unified with anything!

> 
> copy_term([A,B,A]-[A], GoalTerm-[c]) yields T=[c,B,c]

Let's do this stepwise. It's the same as

    copy_term([A,B,A]-[A], Copy),  % creates Copy = [A1,B1,A1]-[A1]
    Copy = T-[c]                   % unifies A1 = c, T = [c,B1,c]

Neither A nor B are unified with anything.


Now, from your other email, I believe that what you want to do
is make a partial copy, i.e. create a copy of a Term (e.g. a
constraint goal) where some variables are fresh copies, and
some are still the same as in the original term. You can do
that as follows:

1. If you have an explicit list VarsToShare of variables that you
   want to be the same in Orig and Copy (i.e. not copied), use  

   copy_term(Orig-VarsToShare, Copy-VarsToShare)

   (what really happens here is that first all variables get copied,
    and then the shared ones get unified back together)

2. If you have an explicit list VarsToCopy of variables that you
   want to be copied (i.e. not shared), use

   copy_term_vars(Orig, Copy, VarsToCopy)

If you experiment with this, I recommend you change the printing mode
?- set_flag(output_mode, "QPmV").
in order to see clearly whether variables are the same or different.


-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
 Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Fri May 02 12:16:00 2003

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:23 PM GMT GMT