MathGroup Archive 2005

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

Search the Archive

Re: Re: Clearing function definitions by argument type?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57272] Re: [mg57247] Re: Clearing function definitions by argument type?
  • From: DrBob <drbob at bigfoot.com>
  • Date: Mon, 23 May 2005 02:20:40 -0400 (EDT)
  • References: <d6mn17$gkf$1@smc.vnet.net> <200505220414.AAA17582@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Clear[f,g]
f[x_]:=g[x]

g[x_]:=g[x]=x^2
f/@Range@10

{1,4,9,16,25,36,49,64,81,100}

Clear@g
g[x_]:=x^3
f/@Range@10

{1,8,27,64,125,216,343,512,729,1000}

Bobby

On Sun, 22 May 2005 00:14:11 -0400 (EDT), David Bailey <dave at Remove_Thisdbailey.co.uk> wrote:

> Gareth Russell wrote:
>> Hi Group,
>>
>> Is there a straightforward way to Clear only definitions that  take
>> certain kinds of arguments? For example, I might have
>>
>> f[x_]:=x^2
>> f[0]=1
>> f[1]=1
>> f[2]=7
>> ...
>>
>> and want to clear all f[number] definitions but not the DelayedSet
>> definition. (Note that the number of f[number] definitions will vary,
>> as will the numbers that each one takes as an argument.)
>>
>> My goal is to clear 'memorized' definitions after an optimization run,
>> where the memorized definitions are generated by a
>>
>> f[x_]:=f[x]=x^2
>>
>> type of function, without clearing the function itself.
>>
>> Gareth Russell
>> Columbia University
>>
> You can see all the assignments in DownValues[g], and you could remove
> the parts of that list that you did not want and then execute
> DownValues[g]:=.....
>
> However, I think it might be easier to rearrange your problem a bit. If
> you 'remember' your answers in another function - g, then you can write
> f as
>
> f[x_] := If[NumberQ[g[x]], g[x], g[x] = x^2]
>
> Then you can just use Clear[g] when you want to start the next problem.
>
> David Bailey
> http://www.dbaileyconsultancy.co.uk
>
>
>
>



-- 
DrBob at bigfoot.com


  • Prev by Date: Re: MultipleListPlot and Log-List plots
  • Next by Date: Re: Re: Bode Plots in Mathematica
  • Previous by thread: Re: Clearing function definitions by argument type?
  • Next by thread: Bode Plots in Mathematica