MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Deleting more subtle then Clear[ ] ?

  • Subject: [mg2239] Re: Deleting more subtle then Clear[ ] ?
  • From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
  • Date: Wed, 18 Oct 1995 05:54:06 GMT
  • Approved: usenet@wri.com
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: University of Colorado, Boulder
  • Sender: daemon at wri.com ( )

In article <DGJqH7.BqD at wri.com>,  <alfred at ca-risc.co.at> wrote:
>
>Well,
>	Let's assume we have a function f[x,y,z] where x and y are VERY big or  
>time consuming lists of numbers or functions.
>	By defining f[x_,y_,z_]:= f[x,y,z] =   I make MMA remember what it did.  
>How can I now tell it to disremember for all f[x,*,*] when I specifically want  
>it to reprocess whatever is dependend on x (i.e. the contents of the file has  
>changed but the name is the same) but NOT on y?

I'm not sure you can do what you want to do, but maybe I misunderstand
what you are trying to do.  If what you mean is that you want to
delete all definitions containing a certain value for x, you can do
it as follows:

First, some example definitions.

    In[1]:=
	f[x_, y_, z_] := f[x, y, z] = x + y + z
	f[1,2,3];
	f[2,3,4];
	f[1,3,5];

The definitions for f are stored in DownValues[f].

    In[5]:=
	DownValues[f]
    Out[5]=
	{Literal[f[1, 2, 3]] :> 6, Literal[f[1, 3, 5]] :> 9, 
	  Literal[f[2, 3, 4]] :> 9, 
	  Literal[f[x_, y_, z_]] :> (f[x, y, z] = x + y + z)}

You can use DeleteCases to remove all definitions whose left-hand
side depends on a particular value of x as follows:

    In[8]:=
	DownValues[f] = DeleteCases[DownValues[f], Literal[_[f[1,__]] :> _]]  
    Out[8]=
	{Literal[f[2, 3, 4]] :> 9, 
	  Literal[f[x_, y_, z_]] :> (f[x, y, z] = x + y + z)}

In this case, I have removed all rules for f[1, *, *] (to use your notation)
but left the others intact.  Note the weird pattern used as the
second argument to DeleteCases.  First of all, the entire thing has to
be wrapped in Literal or else DeleteCases will interpret it as a replacement
rule, rather than a pattern that matches a replacement rule.  Also note
that each left-hand side of DownValues[f] is wrapped in Literal, which is
impossible to match (because the pattern matcher ignores it); hence we
simply match _[f[1, __]].

I hope this is what you're trying to do.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon


  • Prev by Date: Re: Sinh, Cosh and all that
  • Next by Date: Re: simultaneous equations
  • Previous by thread: Deleting more subtle then Clear[ ] ?
  • Next by thread: Deleting more subtle then Clear[ ] ?