MathGroup Archive 2002

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

Search the Archive

Re: removing rules from function definitions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33042] Re: [mg33028] removing rules from function definitions
  • From: BobHanlon at aol.com
  • Date: Wed, 27 Feb 2002 00:47:58 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2/26/02 6:52:13 AM, erich.neuwirth at univie.ac.at writes:

>let me explain my problem with a simplified example
>i define
>f[1] := f[1] = 1
>f[n_] /; n > 1 := f[n] = f[n - 1]*2
>after evaluating f[1]
>i have
>
>In[36]:=
>FullForm[DownValues[f]]
>
>Out[36]//FullForm=
>List[RuleDelayed[HoldPattern[f[1]],1],RuleDelayed[HoldPattern[f[2]],2],
>  RuleDelayed[HoldPattern[f[3]],4],RuleDelayed[HoldPattern[f[4]],8],
>  RuleDelayed[HoldPattern[f[5]],16],RuleDelayed[HoldPattern[f[6]],32],
>  RuleDelayed[HoldPattern[f[7]],64],RuleDelayed[HoldPattern[f[8]],128],
>  RuleDelayed[HoldPattern[f[9]],256],
>  RuleDelayed[HoldPattern[f[10]],Times[f[Plus[10,-1]],2]],
> 
>RuleDelayed[HoldPattern[Condition[f[Pattern[n,Blank[]]],Greater[n,1]]],
>    Set[f[n],Times[f[Plus[n,-1]],2]]]]
>
>no i want to remove all the rules which were added during the
>evaluation.
>Drop[DownValues[f],MyPattern]
>essentially allows me to create a new rules list,
>but i cannot get MyPattern right
>
>
>MatchQ[#,RuleDelayed[HoldPattern[f[_Integer],_Integer]]
>
>does not work because HoldPattern gets evaluated,
>but doing it Verbatim does not work either
>because then _Integer is not evakuated and therefore does not work any
>more.
>
>
>i really ned a pattern matching all rules
>
>RuleDelayed[HoldPattern[f[_Integer]],_Integer]
>
>which interprets _Integer nonverbatim, but everything else verbatim.
>can anybody help me?
>

Drop does not work with patterns.  Use DeleteCases.

f[1]:=1;
f[n_Integer?Positive]:=f[n]=f[n-1]*2;

DownValues[f]= DeleteCases[DownValues[f], _?(#[[2]]>1&)];


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: Sound and CDs query. Probably an FAQ but I could not find it.
  • Next by Date: RE: Hint on: Problems converting mathematica notebook to PDF with Acrobat Distiller
  • Previous by thread: removing rules from function definitions
  • Next by thread: Re: removing rules from function definitions