MathGroup Archive 2006

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

Search the Archive

Re: Deleting Selective DownValues

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64033] Re: [mg63984] Deleting Selective DownValues
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 28 Jan 2006 02:23:46 -0500 (EST)
  • References: <200601260843.DAA22208@smc.vnet.net> <91CEB394-BC36-43FD-B1C3-B8E9571581ED@mimuw.edu.pl>
  • Sender: owner-wri-mathgroup at wolfram.com

On 26 Jan 2006, at 10:26, Andrzej Kozlowski wrote:

>
> On 26 Jan 2006, at 08:43, David Park wrote:
>
>> Dear MathGroup,
>>
>> Suppose I have established the following definitions for f, but  
>> not necessarily in the given order.
>>
>> Clear[f]
>> f[x_, y_, z_] := x y z
>> f[a_, b_] := a b
>> f[x_] := x
>> DownValues[f]
>> {HoldPattern[f[x_, y_, z_]] :> x y z, HoldPattern[f[a_, b_]] :> a b,
>>   HoldPattern[f[x_]] :> x}
>>
>> Now I would like to delete the f definition that has a given  
>> number of arguments, say f[a_,b_] with 2 arguments. So I need a  
>> routine:
>>
>> deleteDownValue[label_Symbol,numberOfArgs_Integer?Positive]:= ???
>>
>> which would reset DownValues[label] to eliminate any definition  
>> with numberOfArgs arguments.
>>
>> I have trouble with doing the matches and evaluation sequences.  
>> Can anyone help with this? Many thanks in advance.
>>
>> David Park
>> djmp at earthlink.net
>> http://home.earthlink.net/~djmp/
>>
>
>
> How about something much simpler:
>
> In[1]:=
> Clear[f]
> f[x_, y_, z_] := x*y*z
> f[a_, b_] := a*b
> f[x_] := x
> DownValues[f]
>
> Out[5]=
> {HoldPattern[f[x_, y_, z_]] :> x*y*z,
>   HoldPattern[f[a_, b_]] :> a*b, HoldPattern[f[x_]] :> x}
>
> In[6]:=
> f[x_, y_] =.
>
> In[7]:=
> DownValues[f]
>
> Out[7]=
> {HoldPattern[f[x_, y_, z_]] :> x*y*z,
>   HoldPattern[f[x_]] :> x}
>
> ??
>
> Andrzej Kozlowski


It seems to me that the above approach  (f[x_, y_] =.), which does  
not refer to DownValues at all, is the simplest possible way to solve  
this particular problem (for two variables) and in practical  
situations nothing more would be needed. One can just as easily  
define a function that would apply it to any any function f:

M[f_] := f[x_, y_] =.

It seems however harder to use this method to create a function that  
would do this for any number of variables n  (although I can't  
imagine any practical use for such a function) but it can be done:


M[f_, n_] :=
      ReleaseHold[Hold[f[##] =.] & @@ (Pattern[#, Blank[]] & /@ Table 
[Unique[
       u], {n}])]

e.g.

Clear[f]
f[x_, y_, z_] := x*y*z
f[a_, b_] := a*b
f[x_] := x

M[f, 3]


DownValues[f]


{HoldPattern[f[a_, b_]] :> a*b, HoldPattern[f[x_]] :> x}

Andrzej Kozlowski




  • Prev by Date: Re: numerical derivatives at very high x-values: precision problem
  • Next by Date: Re: numerical derivatives at very high x-values: precision problem
  • Previous by thread: Re: Deleting Selective DownValues
  • Next by thread: Re: Deleting Selective DownValues